基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,409 @@
|
||||
using DevExpress.Utils;
|
||||
using DevExpress.XtraEditors;
|
||||
using DevExpress.XtraEditors.Controls;
|
||||
using DevExpress.XtraEditors.Events;
|
||||
using DevExpress.XtraEditors.Repository;
|
||||
using DevExpress.XtraGrid.Columns;
|
||||
using DevExpress.XtraGrid.Views.Base;
|
||||
using DevExpress.XtraGrid.Views.Grid;
|
||||
using Lskj.Business.Impl;
|
||||
using Lskj.Control;
|
||||
using Lskj.Core;
|
||||
using Lskj.Model;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lskj.PubPdfSign
|
||||
{
|
||||
public partial class FrmUpload : BaseForm
|
||||
{
|
||||
public FrmUpload()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Load += OnFrmMainLoad;
|
||||
this.FormClosed += OnFrmMainClosed;
|
||||
}
|
||||
/// <summary>
|
||||
/// model
|
||||
/// </summary>
|
||||
public DynamicPdfSignModel PdfSignModel;
|
||||
/// <summary>
|
||||
/// AdapterObj
|
||||
/// </summary>
|
||||
public SqlDataAdapter AdapterObj { get; set; }
|
||||
/// <summary>
|
||||
/// 关闭窗口
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnFrmMainClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
this.pdfEditorEx.CloseDocument();
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化控件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnFrmMainLoad(object sender, EventArgs e)
|
||||
{
|
||||
this.btn_UpLoad.Click += OnBtnUpLoadClick;
|
||||
this.btn_UpDelete.Click += OnBtnUpDeleteClick;
|
||||
this.btn_UpSave.Click += OnBtnUpSaveClick;
|
||||
this.btn_AddTemp.Click += OnBtnAddTempClick;
|
||||
this.gridView.RowClick += OnGridViewRowClick;
|
||||
this.gridView.FocusedRowObjectChanged += OnGridViewFocusedRowObjectChanged;
|
||||
this.gridView.CustomDrawCell += OnGridViewCustomDrawCell;
|
||||
this.gridView.CustomDrawRowIndicator += OnGridViewCustomDrawRowIndicator;
|
||||
this.gridView.CellValueChanged += OnGridViewCellValueChanged;
|
||||
InitGridColumns();
|
||||
|
||||
pdfEditorEx.StepTable = MainImpl.GetDataTableResult($"SELECT stepCode, stepName FROM P_systemdlltabflow WHERE typecode = '{PdfSignModel.TypeCode}' UNION ALL SELECT '9999' AS stepCode, '时间' AS stepName;");
|
||||
SetGridViewDataSource(GetAdapterResult($"select * from p_SignAccraditationTable"));
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加模板
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnBtnAddTempClick(object sender, EventArgs e)
|
||||
{
|
||||
using (FrmDesign frmMain = new FrmDesign())
|
||||
{
|
||||
frmMain.ShowDialog();
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable("select * from P_SignTempTable");
|
||||
versionGridLookUpEdit.DataSource = dataTable;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存按钮点击
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnBtnUpSaveClick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dataTable = this.gcMain.DataSource as DataTable;
|
||||
if (dataTable.Rows.Cast<DataRow>().Where(n => string.IsNullOrWhiteSpace(n["versionCode"] + "")).Count() > 0)
|
||||
{
|
||||
MessageUtil.Show("版本名称不能为空");
|
||||
return;
|
||||
}
|
||||
int result = this.AdapterObj.Update(dataTable);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show($"保存失败,原因:{ex.Message}");
|
||||
return;
|
||||
}
|
||||
MessageUtil.Show("保存成功");
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除按钮点击
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnBtnUpDeleteClick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
int[] rowids = this.gridView.GetSelectedRows();
|
||||
if (rowids == null || rowids.Length == 0)
|
||||
{
|
||||
MessageUtil.Show("请选择需要删除的数据");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
DialogResult result = MessageUtil.Show($"确定要删除选中{rowids.Length}条数据?", MessageBoxButtons.YesNo);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
ArrayList localDeletes = new ArrayList();
|
||||
Dictionary<string, string> mList = new Dictionary<string, string>();
|
||||
List<string> delToPosts = new List<string>();
|
||||
foreach (int rowid in rowids)
|
||||
{
|
||||
DataRow rowData = this.gridView.GetDataRow(rowid);
|
||||
if (rowData.RowState != DataRowState.Added)
|
||||
{
|
||||
string fieldValue = rowData["id"] + "";
|
||||
string sqlValue = string.Format("delete from p_SignAccraditationTable where id = '{0}'", fieldValue);
|
||||
mList.Add(fieldValue, sqlValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
localDeletes.Add(rowid);
|
||||
}
|
||||
}
|
||||
if (mList.Count > 0)
|
||||
{
|
||||
string hintMsg = "删除结果如下:\n";
|
||||
foreach (string primaryKey in mList.Keys)
|
||||
{
|
||||
try
|
||||
{
|
||||
string deleteSql = mList[primaryKey];
|
||||
SqlHelper.ExecuteNonQuery(deleteSql);
|
||||
hintMsg += "记录[" + primaryKey + "]删除成功.\n";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
hintMsg += "记录[" + primaryKey + "]删除失败,原因:" + ex.Message + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (localDeletes.Count > 0)
|
||||
{
|
||||
// 删除选中且未保存的数据
|
||||
for (int i = localDeletes.Count - 1; i >= 0; i--)
|
||||
{
|
||||
this.gridView.DeleteRow((int)localDeletes[i]);
|
||||
}
|
||||
MessageUtil.Show("删除成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("无法删除");
|
||||
}
|
||||
}
|
||||
SetGridViewDataSource(GetAdapterResult($"select * from p_SignAccraditationTable"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 上传按钮点击
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnBtnUpLoadClick(object sender, EventArgs e)
|
||||
{
|
||||
using (OpenFileDialog dialog = new OpenFileDialog())
|
||||
{
|
||||
dialog.Multiselect = true;//该值确定是否可以选择多个文件
|
||||
dialog.Title = "请选择文件";
|
||||
dialog.Filter = "PDF文件(*.pdf)|*.pdf";
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
foreach (string fileFullName in dialog.FileNames)
|
||||
{
|
||||
AddGridViewRecord(fileFullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 版本改变时改变签名位置
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnGridViewCellValueChanged(object sender, CellValueChangedEventArgs e)
|
||||
{
|
||||
if (e.Column.FieldName.Equals("versionCode"))
|
||||
{
|
||||
string versionCode = this.gridView.GetFocusedRowCellValue(e.Column) + "";
|
||||
if (!string.IsNullOrWhiteSpace(versionCode))
|
||||
{
|
||||
this.pdfEditorEx.ClearSignBox();
|
||||
this.pdfEditorEx.LoadSign(versionCode, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 点击指定行
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnGridViewRowClick(object sender, RowClickEventArgs e)
|
||||
{
|
||||
DataRow dataRow = this.gridView.GetDataRow(e.RowHandle);
|
||||
if (dataRow != null)
|
||||
{
|
||||
string versionCode = dataRow.Table.Columns.Contains("versionCode") ? dataRow["versionCode"] + "" : "";
|
||||
this.pdfEditorEx.VersionCode = versionCode;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 选中行改变时
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnGridViewFocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e)
|
||||
{
|
||||
DataRow dataRow = this.gridView.GetFocusedDataRow();
|
||||
if (dataRow != null)
|
||||
{
|
||||
string versionCode = dataRow.Table.Columns.Contains("versionCode") ? dataRow["versionCode"] + "" : "";
|
||||
this.pdfEditorEx.VersionCode = versionCode;
|
||||
this.pdfEditorEx.OpenLocalFile(dataRow, false);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 选中行颜色
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnGridViewCustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
|
||||
{
|
||||
if (e.RowHandle == gridView.FocusedRowHandle)
|
||||
{
|
||||
e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示表格序号
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnGridViewCustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
|
||||
if (e.Info.IsRowIndicator)
|
||||
{
|
||||
if (e.RowHandle >= 0)
|
||||
{
|
||||
e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 弹出框弹出时
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnSearchEditQueryPopUp(object sender, CancelEventArgs e)
|
||||
{
|
||||
int popWidth = 0;
|
||||
GridLookUpEdit edit = (sender as GridLookUpEdit);
|
||||
foreach (GridColumn col in edit.Properties.View.Columns)
|
||||
{
|
||||
int colWidth = col.GetBestWidth();
|
||||
col.Width = colWidth;
|
||||
popWidth += colWidth;
|
||||
}
|
||||
edit.Properties.PopupFormSize = new Size(popWidth, edit.Properties.PopupFormSize.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置数据源
|
||||
/// </summary>
|
||||
private int SetGridViewDataSource(SqlDataAdapter adapter, bool selectRowHandler = true)
|
||||
{
|
||||
if (adapter == null) return 0;
|
||||
try
|
||||
{
|
||||
this.AdapterObj = adapter;
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet, "SetGridViewDataSource");
|
||||
SqlCommandBuilder cb = new SqlCommandBuilder(this.AdapterObj);
|
||||
DataTable dt = dataSet.Tables[0];
|
||||
this.gcMain.DataSource = dt;
|
||||
this.gridView.BestFitColumns();
|
||||
if (selectRowHandler)
|
||||
this.gridView.SelectRow(this.gridView.FocusedRowHandle);
|
||||
return dataSet.Tables[0] != null ? dataSet.Tables[0].Rows.Count : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 直接表格添加数据
|
||||
/// </summary>
|
||||
/// <param name="fullName"></param>
|
||||
private void AddGridViewRecord(string fullName)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dt = this.gcMain.DataSource as DataTable;
|
||||
DataRow dataRow = dt.NewRow();
|
||||
dataRow["localPath"] = fullName;
|
||||
dataRow["pdfUrl"] = fullName;
|
||||
string fileName = Path.GetFileNameWithoutExtension(fullName);
|
||||
dataRow["fileName"] = fileName;
|
||||
dataRow["stepCode"] = "100";
|
||||
dataRow["operator"] = ERPInfo.Instance.UserId;
|
||||
dt.Rows.Add(dataRow);
|
||||
this.gridView.UpdateCurrentRow();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取数据
|
||||
/// </summary>
|
||||
/// <param name="sqlValue"></param>
|
||||
/// <returns></returns>
|
||||
private SqlDataAdapter GetAdapterResult(string sqlValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sqlValue)) return new SqlDataAdapter();
|
||||
return SqlHelper.ExecuteAdapter(CommandType.Text, sqlValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return new SqlDataAdapter();
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化表格列
|
||||
/// </summary>
|
||||
private void InitGridColumns()
|
||||
{
|
||||
versionGridLookUpEdit.View.OptionsView.ShowIndicator = false;
|
||||
versionGridLookUpEdit.View.OptionsView.ColumnAutoWidth = false;
|
||||
versionGridLookUpEdit.PopupSizeable = true;
|
||||
versionGridLookUpEdit.PopupResizeMode = ResizeMode.Default;
|
||||
versionGridLookUpEdit.AllowFocused = true;
|
||||
versionGridLookUpEdit.ImmediatePopup = true;
|
||||
versionGridLookUpEdit.ShowFooter = false;
|
||||
versionGridLookUpEdit.NullText = "";
|
||||
versionGridLookUpEdit.TextEditStyle = TextEditStyles.Standard;
|
||||
versionGridLookUpEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||||
versionGridLookUpEdit.AllowNullInput = DefaultBoolean.False;
|
||||
versionGridLookUpEdit.ShowPopupShadow = true;
|
||||
versionGridLookUpEdit.DisplayMember = "versionName";
|
||||
versionGridLookUpEdit.ValueMember = "id";
|
||||
versionGridLookUpEdit.View.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
|
||||
GridColumn valueColumn = new GridColumn();
|
||||
valueColumn.Name = valueColumn.FieldName = "id";
|
||||
valueColumn.Caption = "编码";
|
||||
valueColumn.Visible = true;
|
||||
GridColumn textColumn = new GridColumn();
|
||||
textColumn.Name = textColumn.FieldName = "versionName";
|
||||
textColumn.Caption = "版本名称";
|
||||
textColumn.Visible = true;
|
||||
versionGridLookUpEdit.View.Columns.AddRange(new GridColumn[] { valueColumn, textColumn });
|
||||
versionGridLookUpEdit.QueryPopUp += new CancelEventHandler(OnSearchEditQueryPopUp);
|
||||
gcMain.RepositoryItems.Add(versionGridLookUpEdit);
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable("select * from P_SignTempTable");
|
||||
versionGridLookUpEdit.DataSource = dataTable;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user