using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid; using DevExpress.Utils; using DevExpress.XtraTab; using CommonLib; using Lskj.Common; using Lskj.MyControl; using DevExpress.XtraGrid.Columns; using CommonLib.utils; using CommonLib.data; using DevExpress.XtraBars; using System.Collections; using Lskj.MyControl.LookUp; using ControlLib.inh; using Lskj.PubUtils; using System.Text.RegularExpressions; using Lskj.MyControl.PrintMoude; using Lskj.PubBill; namespace Lskj.PubBillInfo { public partial class FrmMain : FormBase { #region 属性 /// /// 目标打开dll /// public string TargetDLLCoid { get; set; } /// /// 单据Id /// public string billDocumentId { get; set; } /// /// 流程编码 /// public string stepCode { get; set; } public string OverBacked { get; set; } public string billPrintSQL = string.Empty; public string billPrintSQL1 = string.Empty; public string billPrintType = string.Empty; public string billModuleFile = string.Empty; public string billPrintSQL2 = string.Empty; #endregion #region 私有属性 /// ///单据DLLInfo /// private DataTable dtBillInfoFiled { get; set; } /// /// 单据类型model /// private DataRow typeModel { get; set; } /// /// 明细明细列表 /// private DataTable attachList; private DataTable dtType; private DataTable dtFileds; private string DirId = string.Empty; private string AuditLoadDetailFlag; private string Formkey = string.Empty; //private Dictionary ctrModelList = new Dictionary(); /// /// 统计列 /// private DataTable dtSum = new DataTable(); private string MasterSql = string.Empty; private string DetailSql = string.Empty; private string masterTable = string.Empty; private string detailTable = string.Empty; private string billSeq = string.Empty;//单据编号 private string prefix = string.Empty;//单据前缀 private string column_prefix= string.Empty; private Font _font = new Font("宋体", 20, FontStyle.Bold); private Font _font1 = new Font("宋体", 18, FontStyle.Bold); private Brush _brush = new SolidBrush(Color.Red); private Pen _pen = new Pen(Color.Red, 2f); private float _angle = -20f; private string _text = "已审核"; private string _textPrint = "打印0次"; private string _text_collect = ""; /// /// 主打印sql /// private string _mainPrintSql; /// /// 打印其他参数条件 /// private string _printModeCond; /// /// 打印完成后添加数据用到的参数 /// private List _printSaveParams; /// /// 是否直接打印 /// private bool _isExcPrint; /// /// 审批意见 /// private string AuditAdvice = string.Empty; /// /// 返审 /// private string BackSelected = string.Empty; /// /// 该单据主信息 /// private DataRow dtBillInfoRow; #endregion #region 构造函数 public FrmMain() { InitializeComponent(); gridBillInfo.gridView.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(gridView_RowCellClick); gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center; gridBillInfo.gridView.IndicatorWidth = 40; } #endregion #region 初始化数据 protected override void OnLoad(EventArgs e) { gridBillInfo.gridControl.Paint += new PaintEventHandler(gridBillInfo_Paint); if (!string.IsNullOrEmpty(FormText)) { this.Text = this.Text + " 【" + FormText + "】 单据号:【" + billDocumentId + "】"; } DLLCoid = TargetDLLCoid; DataTable dtType = SqlHelper.ExecuteDataSet("select * from p_systembilltype where typeCode='" + DLLCoid + "'").Tables[0]; if (dtType != null && dtType.Rows.Count > 0) { billPrintType = dtType.Rows[0]["billPrintType"].ToString(); billPrintSQL = dtType.Rows[0]["billPrintSQL"].ToString(); billPrintSQL1 = dtType.Rows[0]["billPrintSQL1"].ToString(); billPrintSQL2 = dtType.Rows[0]["billPrintSQL2"].ToString(); billModuleFile = dtType.Rows[0]["billModuleFile"].ToString(); column_prefix = PubClass.GetColumnPrefix(dtType.Rows[0]["mastertable"].ToString()); if (dtType.Columns.Contains("AuditLoadDetailFlag")) { AuditLoadDetailFlag = dtType.Rows[0]["AuditLoadDetailFlag"] + ""; } if (string.IsNullOrEmpty(AuditLoadDetailFlag) || AuditLoadDetailFlag == "0") { gridBillInfo.gridView.RowCellClick +=new RowCellClickEventHandler(gridView_RowCellClick); } else { gridBillInfo.gridView.DoubleClick += new EventHandler(gridView_DoubleClick); } } gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center; string billInfoSql = "select * from p_systembillinfo where typecode=" + DLLCoid + " and isnull(isvisible,0)=0"; dtBillInfoFiled = SqlHelper.ExecuteDataSet(billInfoSql).Tables[0]; //txtCheckName.Text = OperatorName; //txtCheckName.Enabled = false; //txtCheckDate.Enabled = false; BindCheckList(); BindTab(); BindBill(); string isSumSql = "select * from p_systembillDetail where typeCode=" + DLLCoid + " and isnull(isVisible,0)=0 and isnull(calcExpr,'')<>''order by calcorder asc"; dtSum = SqlHelper.ExecuteDataSet(isSumSql).Tables[0]; //string sql = "select Mix_apellation from P_BaseMixInfoTab a where a.Tag =1201"; //txtYj.setDataSource(sql, "Mix_apellation", "Mix_apellation"); //txtYj.getComboBox.SelectedValueChanged += new EventHandler(getComboBox_SelectedValueChanged); //txtYj.getComboBox.DropDownStyle = ComboBoxStyle.DropDownList; //单据颜色 string colorSql = "select * from p_systemwordbookcolor where tab='" + "BILLDETAIL_" + Formkey + "'"; DataTable dtColor = SqlHelper.ExecuteDataSet(colorSql).Tables[0]; gridBillInfo.RowColorCondtion = dtColor; GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", gridBillInfo.gridControl); gm.DirId = DirId; gm.BindGridMenu("BILLDETAIL_" + DLLCoid); InitPMenu(); txt_Billdocument_Id.Text = billDocumentId; if (!string.IsNullOrEmpty(billModuleFile)) { //pMprint String[] strs = billModuleFile.Split('|'); for (int i = 0; i < strs.Length; i++) { BarButtonItem bbi = new BarButtonItem(); int index = i + 1; bbi.Caption = strs[i].Replace(".rmf", ""); bbi.Tag = strs[i]; bbi.ItemClick += new ItemClickEventHandler(print_ItemClick); pMprint.AddItem(bbi); } } if (OverBacked == "1") { panel1.Visible = false; } GetPrintOtherParam(); } private void gridView_DoubleClick(object sender, EventArgs e) { try { int[] rows = gridBillInfo.gridView.GetSelectedRows(); if (rows.Length < 1) return; DataRow row = gridBillInfo.gridView.GetDataRow(rows[0]); foreach (DataRow item in attachList.Rows) { GridControlEx gce = this.Controls.Find("gce_" + item["id"], true)[0] as GridControlEx; string sql = gce.Sql; List param = PubClass.GetParamValue(gce.Sql); foreach (string s in param) { string filedName = s.Replace("{", "").Replace("}", ""); sql = sql.Replace(s, row[filedName].ToString()); } gce.ConstSql = sql; gce.SetDataSource(sql); } } catch (Exception) { } } /// /// 说明:获取打印完成后进行数据库业务处理的参数 /// 创建人:姜棚 /// 创建日期:2018-07-19 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void GetPrintOtherParam() { //取得打印完成后的参数 if (!string.IsNullOrEmpty(billPrintSQL)&&billPrintSQL.Contains("<<")) { string[] strs = billPrintSQL.Split(new[] { ">>" }, 2, StringSplitOptions.None); _mainPrintSql = strs[1]; _printModeCond = strs[0].Replace("<<", ""); } if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) { string[] str = _printModeCond.Split(';'); string sql = string.Format("select * from v_systemdlltab where DllCoid='{0}'", str[0]); DataTable dt = SqlHelper.ExecuteDataTable(sql); if (dt == null || dt.Rows.Count == 0) return; string tableName = dt.Rows[0]["TableName"] + ""; string modetype = dt.Rows[0]["modType"] + ""; string sql2 = string.Format("select column_prefix from p_systemtables where lower(table_name)='{0}'", tableName); DataTable dt2 = SqlHelper.ExecuteDataTable(sql2); if (dt2 == null || dt2.Rows.Count == 0) return; string comprefix = dt2.Rows[0]["column_prefix"] + ""; string sql3 = string.Format("select top 1 fieldname from P_systemwordbooktab where tab='{0}' order by orderid", str[0]); DataTable dt3 = SqlHelper.ExecuteDataTable(sql3); string primaryKey = modetype == "1" ? dt3.Rows[0]["fieldname"] + "" : comprefix + "billdocument_id"; //表名,列前缀,主键字段,主键值,模块编号,主打印Sql _printSaveParams = new List() { tableName, comprefix, primaryKey, str[1], str[0], _mainPrintSql }; //判断是否直接打印 modetype 区别单据和基础档案模块 switch (modetype) { case "1": string sql4 = string.Format("select * from P_systemdlltab where DllCoid='{0}'", str[0]); DataTable dt4 = SqlHelper.ExecuteDataTable(sql4); if (dt4 != null && dt4.Rows.Count > 0) _isExcPrint = dt4.Rows[0]["printType"] + "" == "3"; break; case "2": string sql5 = string.Format("select mastertable,overbacksql,overbackkey,overbackoper,overbackcond,prefix,formkey,billPrintType from p_systembilltype where typecode='{0}'", str[0]); //BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.Instance.GetPubAuditProperty(str[0])); DataTable dt5 = SqlHelper.ExecuteDataTable(sql5); if (dt5 != null && dt5.Rows.Count > 0) _isExcPrint = dt5.Rows[0]["billPrintType"] + "" == "3"; break; } } } /// /// 打印 /// /// /// protected void print_ItemClick(object sender, ItemClickEventArgs e) { string billNo = txt_Billdocument_Id.Text; billModuleFile = e.Item.Tag + ""; if (!string.IsNullOrEmpty(billNo)) { string sql = PubClass.ReqSqlParam(MasterSql, OperatorId, OperatorName); List list = PubClass.GetParamValue(sql); foreach (string str in list) sql = sql.Replace(str, billNo); DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; DataRow row = null; if (dt != null && dt.Rows.Count > 0) { //AddForm(pl_right_main, 2, true); dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; row = dt.Rows[0]; string path = PubUtil.AbsolutelyPath + "lib/P_PubPrint.lsp"; billPrintSQL = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL, OperatorId, OperatorName)); billPrintSQL1 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL1, OperatorId, OperatorName)); billPrintSQL2 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL2, OperatorId, OperatorName)); string mainSql = string.Empty; List tmpSqls = billPrintSQL2.Split(';').ToList(); if (_printSaveParams != null && _printSaveParams.Count > 0) { _printSaveParams[5] = mainSql = PubClass.ReqSql(row, _mainPrintSql); //单据编号 _printSaveParams[3] = row.Table.Columns.Contains(_printSaveParams[2] + "") ? row[_printSaveParams[2]] + "" : billNo; tmpSqls.Add(billPrintSQL1); tmpSqls.Add(mainSql); } if (billModuleFile.Contains(PrintUtil.TemplateFlag)) { PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter); PrintUtil.TemplatePrint(tmpSqls, billModuleFile, _isExcPrint); } else { PubUtil.LoadDelphiDll(path, path, billModuleFile, billPrintSQL, billPrintSQL1, Convert.ToInt32(billPrintType), billPrintSQL2); } } else { DialogResult dr = XtraMessageBox.Show("你确定要保存单据后打印?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { //AddForm(pl_right_main, 1, true); dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; row = dt.Rows[0]; string path = PubUtil.AbsolutelyPath + "lib/P_PubPrint.lsp"; billPrintSQL = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL, OperatorId, OperatorName)); billPrintSQL1 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL1, OperatorId, OperatorName)); billPrintSQL2 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL2, OperatorId, OperatorName)); string mainSql = string.Empty; List tmpSqls = billPrintSQL2.Split(';').ToList(); if (_printSaveParams != null && _printSaveParams.Count > 0) { _printSaveParams[5] = _mainPrintSql = PubClass.ReqSql(row, _mainPrintSql); _printSaveParams[3] = row.Table.Columns.Contains(_printSaveParams[2] + "") ? row[_printSaveParams[2]] + "" : row["billdocument_id"] + ""; tmpSqls.Add(billPrintSQL1); tmpSqls.Add(_mainPrintSql); } if (billModuleFile.Contains(PrintUtil.TemplateFlag)) { PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter); PrintUtil.TemplatePrint(tmpSqls, billModuleFile, _isExcPrint); } else { PubUtil.LoadDelphiDll(path, path, billModuleFile, billPrintSQL, billPrintSQL1, Convert.ToInt32(billPrintType), billPrintSQL2); } } } } } /// /// 说明:打印完成后回调 /// 创建人:姜棚 /// 创建日期:2018-07-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The e. private void OnReportPrintAfter(object sender, EventArgs e) { //打印完成后添加数据库 int result = SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]); } /// /// 说明:打印完成成功后数据业务处理 /// 创建人:姜棚 /// 创建日期:2018-07-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public int SavePrintRecord(string tableName, string prefix, string primaryKey, string primaryValue, string modeCode) { string sqlValue = string.Format(@"update {0} set {1}printCount=isnull({1}printCount,0)+1, {1}printLastTime=getdate(),{1}printLastOper='{4}' where {2}='{3}'", tableName, prefix, primaryKey, primaryValue, ERPInfo.Instance.EmployeeId); int i = SqlHelper.ExecuteNonQuery(sqlValue); if (i < 0) return -1; string sqlValue2 = string.Format(@"insert into p_systemPrintDetails (typeCode,sourcecode,OperatorId,operatedate,OperType) values ('{0}','{1}','{2}','{3}','{4}')", modeCode, primaryValue, ERPInfo.Instance.EmployeeId, DateTime.Now, 3); return SqlHelper.ExecuteNonQuery(sqlValue2); } protected void getComboBox_SelectedValueChanged(object sender, EventArgs e) { // txtRemark.Text = txtYj.getComboBox.Text; } #endregion protected void gridView_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { try { int[] rows = gridBillInfo.gridView.GetSelectedRows(); if (rows.Length < 1) return; DataRow row = gridBillInfo.gridView.GetDataRow(rows[0]); foreach (DataRow item in attachList.Rows) { GridControlEx gce = this.Controls.Find("gce_" + item["id"], true)[0] as GridControlEx; string sql = gce.Sql; List param = PubClass.GetParamValue(gce.Sql); foreach (string s in param) { string filedName = s.Replace("{", "").Replace("}", ""); sql = sql.Replace(s, row[filedName].ToString()); } gce.ConstSql = sql; gce.SetDataSource(sql); } } catch (Exception) { } } #region 处理Grid计算 private void gvBill_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { try { DataRow gvRow = gridBillInfo.gridView.GetDataRow(e.RowHandle); foreach (DataRow row in dtSum.Rows) { string calcExpr = row["calcExpr"].ToString(); if (e.Column.FieldName != row["fieldName"].ToString()) { List listParam = PubClass.GetParamValue(calcExpr); foreach (string str in listParam) { string filed = str.Replace("{", "").Replace("}", ""); string filedValue = gvRow[filed].ToString(); if (string.IsNullOrEmpty(filedValue)) filedValue = "0"; calcExpr = calcExpr.Replace(str, filedValue + ""); } string result = Lskj.Common.Evaluator.Eval(calcExpr).ToString(); gridBillInfo.gridView.SetRowCellValue(e.RowHandle, gridBillInfo.gridView.Columns[row["fieldName"].ToString()], result); } } } catch { } } #endregion /// /// 检查结果 /// public void BindCheckList() { DataTable dt = SqlHelper.ExecuteDataSet("select case when stepcode=0 then stepName else REPLACE(REPLACE(REPLACE(operDirection,'R','退'),'F','审'),'Q','关闭') end as sh,* from wms_billflowstep where flowSourceKey='" + billDocumentId + "' order by id asc").Tables[0]; gcAttach.DataSource = dt; string sql = "select stepCode from Wms_BillJoinMainTab where Billdocument_Id='" + DLLCoid + "'"; //string sql2 = "select * from p_systembillflow where typeCode='" + DLLCoid + "' and stepCode='" + stepCode + "'"; //DataTable dt2 = SqlHelper.ExecuteDataSet(sql2).Tables[0]; //if (dt2 != null && dt2.Rows.Count > 0) //{ // gbName.Text = dt2.Rows[0]["stepName"].ToString(); // txtCheckName.LabelText = dt2.Rows[0]["stepName"].ToString(); //} dtType = SqlHelper.ExecuteDataSet("select * from p_systembilltype where typeCode='" + DLLCoid + "'").Tables[0]; if (dtType != null && dtType.Rows.Count > 0) { MasterSql = dtType.Rows[0]["MasterSql"].ToString(); DetailSql = dtType.Rows[0]["DetailSql"].ToString(); prefix = dtType.Rows[0]["prefix"].ToString(); billSeq = dtType.Rows[0]["billSeq"].ToString(); masterTable = dtType.Rows[0]["masterTable"].ToString(); detailTable = dtType.Rows[0]["detailTable"].ToString(); DirId = dtType.Rows[0]["DirId"].ToString(); Formkey = dtType.Rows[0]["Formkey"].ToString(); BackSelected = "0"; if (dtType.Columns.Contains("backSelected")) BackSelected = dtType.Rows[0]["backSelected"].ToString(); if (BackSelected == "") BackSelected = "0"; } } #region 绑定选项卡 /// /// 绑定选项卡 /// public void BindTab() { tabDetailMain.TabPages.Clear(); attachList = SqlHelper.ExecuteDataSet("select * from P_systembillauditAttach where typeCode='" + DLLCoid + "' and stepcode='" + stepCode + "' and isnull(isVisible,0)=0").Tables[0]; if (attachList.Rows.Count == 0) { plbillInfo.Height = 0; plbillInfo.Visible = false; return; } foreach (DataRow row in attachList.Rows) { XtraTabPage tabPage = new XtraTabPage(); tabPage.Padding = new System.Windows.Forms.Padding(2); tabPage.Name = "tab" + row["id"]; tabPage.Text = row["attachName"] + ""; tabPage.Tag = row["id"]; GridControlEx gce = new GridControlEx(); DataTable dtColor = SqlHelper.ExecuteDataSet("select * from p_systemwordbookcolor where tab='" + row["formkey"] + "' and isnull(useflag,0)=0 order by orderid").Tables[0]; gce.RowColorCondtion = dtColor; gce.gridView.RowCellStyle += new RowCellStyleEventHandler(gridView_RowCellStyle); gce.Name = "gce_" + row["id"]; gce.Dock = DockStyle.Fill; gce.Sql = row["attachSql"] + ""; string sql = "select * from p_systembillauditAttachDetail where attachId=" + row["id"] + " and isnull(isVisible,0)=0 order by orderid"; gce.SetColumns(sql); GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", gce.gridControl, RefreshBill); gm.DirId = DirId; string attachKey = row["formkey"] + ""; gm.BindGridMenu(attachKey); tabPage.Controls.Add(gce); tabDetailMain.TabPages.Add(tabPage); } } #endregion #region 初始常用工具 /// /// 初始常用工具 /// public void InitPMenu() { string sql = "select * from p_systempopupmenu where menuType=1 and tab='" + DLLCoid + "' and visible=0"; DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; foreach (DataRow item in dt.Rows) { BarButtonItem bbi = new BarButtonItem(); bbi.Caption = item["menuname"] + ""; bbi.Tag = item; pMenu.AddItem(bbi); bbi.ItemClick += new ItemClickEventHandler(bbi_ItemClick); } if (dt.Rows.Count == 0) { dpbTools.Visible = false; btnAtt.Location = new Point(6, 191); btnAtt.Width = 226; } } protected void bbi_ItemClick(object sender, ItemClickEventArgs e) { DataRow row = e.Item.Tag as DataRow; int actionType = Convert.ToInt32(row["actiontype"]); string action = row["action"].ToString(); string dllName = row["dllname"].ToString(); List valueList = new List(); valueList.Add(row["dllpar1"].ToString()); valueList.Add(row["dllpar2"].ToString()); valueList.Add(row["dllpar3"].ToString()); valueList.Add(row["dllpar4"].ToString()); valueList.Add(row["dllpar5"].ToString()); valueList.Add(row["dllpar6"].ToString()); valueList.Add(row["dllpar7"].ToString()); valueList.Add(row["dllpar8"].ToString()); valueList.Add(row["dllpar9"].ToString()); valueList.Add(row["dllpar10"].ToString()); if (actionType == 2) { #region 打开DLL List paremList = new List(); foreach (string item in valueList) { //解析sql if (item.IndexOf('@') != -1) { string sql = item.Replace("@", ""); List sqlpar = PubClass.GetParamValue(sql); foreach (string s in sqlpar) { string fName = "txt_" + s.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { string ctlValue = PubControl.GetControlText(c[0]); sql = sql.Replace(s, ctlValue + ""); } } string param = SqlHelper.ExecuteScalar(CommandType.Text, sql) + ""; paremList.Add(param); } else if (item.StartsWith("{")) { string fName = "txt_" + item.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { string ctlValue = PubControl.GetControlText(c[0]); paremList.Add(ctlValue); } else paremList.Add(item); } else if (item.StartsWith("#")) { string sql = item.Replace("#", ""); List sqlpar = PubClass.GetParamValue(sql); foreach (string s in sqlpar) { string fName = "txt_" + s.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { string ctlValue = PubControl.GetControlText(c[0]); sql = sql.Replace(s, ctlValue); } } paremList.Add(sql); } else { paremList.Add(item); } } if (dllName == "Lskj.PhotoView.dll") { string[] str = { FormText, OperatorId, OperatorName, Privilege, DLLCoid, paremList[0], paremList[1], paremList[2], paremList[3], paremList[4], paremList[5], paremList[6], paremList[7], paremList[8], paremList[9] }; IForm form = PubUtil.LoadDllForm2("Lskj.PhotoView.dll", str); form.SubForm.ShowDialog(); } else if (dllName == "Lskj.Attachment.dll") { string[] str = { FormText, OperatorId, OperatorName, Privilege, DLLCoid, paremList[0], paremList[1], paremList[2], paremList[3], paremList[4], paremList[5], paremList[6], paremList[7], paremList[8], paremList[9] }; IForm form = PubUtil.LoadDllForm2("Lskj.Attachment.dll", str); form.SubForm.ShowDialog(); } else { string[] str = { FormText, OperatorId, OperatorName, Privilege, DLLCoid, paremList[0], paremList[1], paremList[2], paremList[3], paremList[3], paremList[4], paremList[5], paremList[6], paremList[7], paremList[8], paremList[9] }; IForm form = PubUtil.LoadDllForm(dllName, str); form.SubForm.ShowDialog(); } #endregion } else if (actionType == 1) { #region 执行存储过程 List paremList = new List(); ArrayList sqlParamList = new ArrayList(); foreach (string item in valueList) { //解析sql if (item.IndexOf('@') != -1) { string sql = item.Replace("@", ""); List sqlpar = PubClass.GetParamValue(sql); foreach (string s in sqlpar) { string fName = "txt_" + s.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { sql = sql.Replace(s, c[0].Text + ""); } } string param = SqlHelper.ExecuteScalar(CommandType.Text, sql) + ""; paremList.Add(param); } else if (item.IndexOf('{') != -1) { string p = item; List sqlpar = PubClass.GetParamValue(item); foreach (string s in sqlpar) { string filedName = s.Replace("{", "").Replace("}", ""); if (filedName.Equals("loginname", StringComparison.OrdinalIgnoreCase)) { p = p.Replace(s, OperatorName); } else if (filedName.Equals("loginid", StringComparison.OrdinalIgnoreCase)) { p = p.Replace(s, OperatorId); } else { string fName = "txt_" + s.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { p = p.Replace(s, c[0].Text + ""); } } } paremList.Add(p); } else { paremList.Add(item); } } List paramName = PubClass.GetParamValue(action); string[] paramStr = paramName[0].Replace("{", "").Replace("}", "").Split(','); for (int i = 0; i < paremList.Count; i++) { string item = paremList[i]; if (!string.IsNullOrEmpty(item)) { string paramStr1 = paramStr[i]; SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1), DbTypeConverter.ConvertToSql(FieldType.VarChar)); param.Value = item; sqlParamList.Add(param); } } SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, action.Replace(paramName[0], "").Trim(), (SqlParameter[])sqlParamList.ToArray(typeof(SqlParameter))); XtraMessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); #endregion } else if (actionType == 3) { List paremList = new List(); foreach (string item in valueList) { if (item.IndexOf('@') != -1) { //解析sql string sql = item.Replace("@", ""); List sqlpar = PubClass.GetParamValue(sql); foreach (string s in sqlpar) { string fName = "txt_" + s.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { sql = action.Replace(s, c[0].Text); } } string param = SqlHelper.ExecuteScalar(CommandType.Text, sql) + ""; paremList.Add(param); } else if (item.IndexOf('{') != -1) { string fName = "txt_" + item.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { paremList.Add(c[0].Text); } } else { paremList.Add(item); } } PubUtil.LoadDelphiDll(dllName, paremList[0], paremList[1], paremList[2], paremList[3], Convert.ToInt32(paremList[4]), paremList[5]); } else { //执行SQL #region 执行SQL语句 List pList = PubClass.GetParamValue(action); foreach (string item in pList) { string fName = "txt_" + item.Replace("{", "").Replace("}", ""); Control[] c = pl_right_main.Controls.Find(fName, true); if (c.Length > 0) { action = action.Replace(item, c[0].Text); } } string newSql = action.Replace("{", "@").Replace("}", "").Replace("'", ""); ArrayList parameters = new ArrayList(); for (int i = 0; i < pList.Count; i++) { string filedName = pList[i].Replace("{", "").Replace("}", ""); if (filedName.Equals("loginname", StringComparison.OrdinalIgnoreCase)) { SqlParameter param = new SqlParameter(string.Format("{0}", filedName), DbTypeConverter.ConvertToSql(FieldType.VarChar)); param.IsNullable = true; param.Value = OperatorName; parameters.Add(param); } else if (filedName.Equals("loginid", StringComparison.OrdinalIgnoreCase)) { SqlParameter param = new SqlParameter(string.Format("{0}", filedName), DbTypeConverter.ConvertToSql(FieldType.VarChar)); param.IsNullable = true; param.Value = OperatorId; parameters.Add(param); } else { SqlParameter param = new SqlParameter(string.Format("{0}", filedName), DbTypeConverter.ConvertToSql(FieldType.VarChar)); param.IsNullable = true; param.Value = row[filedName]; parameters.Add(param); } SqlHelper.ExecuteNonQuery(CommandType.Text, newSql, (SqlParameter[])parameters.ToArray(typeof(SqlParameter))); XtraMessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion } } #endregion #region 改变单元格颜色 /// /// 改变单元格颜色 /// /// /// protected void gridView_RowCellStyle(object sender, RowCellStyleEventArgs e) { if (e.RowHandle >= 0) { XtraTabPage tagpage = tabDetailMain.SelectedTabPage; Control[] ctl = tagpage.Controls.Find(tagpage.Name.Replace("tab", "gce_"), true); if (ctl.Length < 1) return; if (ctl[0] == null) return; GridControlEx gce = ctl[0] as GridControlEx; DataRow row = gce.gridView.GetDataRow(e.RowHandle); //颜色集合 DataTable dt = gce.RowColorCondtion as DataTable; //选择列 string cond = string.Empty; string color = string.Empty; string forecolor = string.Empty; if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { List condition = PubClass.GetParamValue(dr["condition"].ToString()); cond = dr["condition"].ToString(); foreach (string item in condition) { string filedName = item.Replace("{", "").Replace("}", ""); cond = cond.Replace(item, row[filedName].ToString()); } cond = PubClass.SqlToCode(cond); color = dr["backcolor"] + ""; forecolor = dr["forcecolor"].ToString() + ""; string obj = Lskj.Common.Evaluator.Eval(cond) + ""; if (obj.IndexOf("true", StringComparison.OrdinalIgnoreCase) != -1) { if (!string.IsNullOrEmpty(color)) { System.Drawing.Color color1 = System.Drawing.ColorTranslator.FromHtml(color); e.Appearance.BackColor = color1; } if (!string.IsNullOrEmpty(forecolor)) { System.Drawing.Color foreColor = System.Drawing.ColorTranslator.FromHtml(forecolor); e.Appearance.ForeColor = foreColor; } } } } //string obj = Evaluator.Eval(cond) + ""; //if (obj.IndexOf("true", StringComparison.OrdinalIgnoreCase) != -1) //{ // if (!string.IsNullOrEmpty(color)) // { // System.Drawing.Color color1 = System.Drawing.ColorTranslator.FromHtml(color); // e.Appearance.BackColor = color1; // } // if (!string.IsNullOrEmpty(forecolor)) // { // System.Drawing.Color foreColor = System.Drawing.ColorTranslator.FromHtml(forecolor); // e.Appearance.ForeColor = foreColor; // } //} } } #endregion #region 单据管理 /// /// 绑定单据 /// public void BindBill() { //创建单据控件 SqlParameter[] p = { new SqlParameter("@formkey",SqlDbType.VarChar,200), new SqlParameter("@modid",SqlDbType.VarChar,50), new SqlParameter("@operatorname",SqlDbType.VarChar,50) }; p[0].Value = Formkey; p[1].Value = DLLCoid; p[2].Value = OperatorName; dtFileds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_getControlLocation", "temp", p).Tables[0]; MyCreateControl myCc = new MyCreateControl(); myCc.LoginId = OperatorId; myCc.LoginName = OperatorName; CreateControlModel ccm = new CreateControlModel(); ccm.dt = dtFileds; ccm.ctr = pl_right_main; ccm.loginid = OperatorId; ccm.loginname = OperatorName; myCc.ParentCtr = pl_right_main; int height = myCc.CreateControlByModel(ccm); int parentHeight = height; DataTable dtParentControl = SqlHelper.ExecuteDataSet(string.Format("select parentHeight from p_systemControlParent where formKey='{0}'", Formkey)).Tables[0]; if (dtParentControl.Rows.Count > 0) { parentHeight = Convert.ToInt32(dtParentControl.Rows[0]["parentHeight"]) - 36; if (parentHeight > height) parentHeight = height; } pl_right_main.Height = parentHeight; //pl_right_main.Height = height; string billModifyFields = string.Empty; DataTable dt = null; //SqlHelper.ExecuteDataSet(string.Format("where typecode={0} and stepcode={1}", DLLCoid, stepCode)).Tables[0]; GridColumnCollection gcc = gridBillInfo.gridView.Columns; if (dt != null && dt.Rows.Count > 0) { //设置单据头修改字段 billModifyFields = dt.Rows[0]["billModifyFields"].ToString() + ","; //设置单据头修改字段结束 string detailModifyFields = dt.Rows[0]["detailModifyFields"] + ""; if (!string.IsNullOrEmpty(detailModifyFields)) { detailModifyFields = detailModifyFields + ","; foreach (GridColumn item in gcc) { if (detailModifyFields.IndexOf(item.FieldName.ToLower() + ",", StringComparison.OrdinalIgnoreCase) != -1) { item.OptionsColumn.AllowEdit = true; item.OptionsColumn.ReadOnly = false; } else { item.OptionsColumn.AllowEdit = false; item.OptionsColumn.ReadOnly = true; } } } } //查询修改列 // string columsSql = string.Format(@"SELECT A.*, ISNULL(B.ISEDITED, 1) AS isEdited // FROM (SELECT * // FROM P_SYSTEMBILLDETAIL A // WHERE TYPECODE = '{0}' // AND ISNULL(ISVISIBLE, 0) = 0 // AND (PRIVILEGEVIEW IS NULL OR EXISTS // (SELECT TOP 1 USERLIST // FROM P_SYSTEMPRIVILEGE // WHERE CHARINDEX(CAST(PRIVTYPEID AS VARCHAR(5)) + ',', // A.PRIVILEGEVIEW + ',') > 0 // AND MODID = '{0}' // AND CHARINDEX('{1}' + ',', USERLIST + ',') > 0))) A // LEFT JOIN (SELECT FIELDNAME, 0 AS isEdited // FROM P_SYSTEMBILLDETAIL A // WHERE TYPECODE = '{0}' // AND ISNULL(ISVISIBLE, 0) = 0 // AND ISNULL(EDITED, 0) = 0 // AND (PRIVILEGEOPER IS NULL OR EXISTS // (SELECT TOP 1 USERLIST // FROM P_SYSTEMPRIVILEGE // WHERE CHARINDEX(CAST(PRIVTYPEID AS VARCHAR(5)) + ',', // A.PRIVILEGEOPER + ',') > 0 // AND MODID = '{0}' // AND CHARINDEX('{1}' + ',', USERLIST + ',') > 0))) B ON A.FIELDNAME =B.FIELDNAME order by orderid asc", DLLCoid, OperatorName); string columsSql = string.Format(@"SELECT distinct isnull(CASE WHEN ISNULL(b.userList,'')='' AND ISNULL(a.PrivilegeView,'')<>'' THEN 0 ELSE width END,0) width, isnull(CASE WHEN ISNULL(c.userList,'')='' AND ISNULL(a.PrivilegeView,'')<>'' THEN 1 ELSE edited END,0) isEdited,a.* FROM p_systembillDetail a LEFT JOIN ( SELECT userList,privTypeId from p_systemPrivilege b where modId = '{0}' AND CHARINDEX(',' + '{1}' + ',', ',' + userList + ',') > 0 ) b on CHARINDEX(',' + CAST(b.privTypeId AS VARCHAR(5)) + ',',',' + a.PrivilegeView + ',') > 0 LEFT JOIN ( SELECT userList,privTypeId FROM p_systemPrivilege WHERE modId = '{0}' AND CHARINDEX(',' + '{1}' + ',', ',' + USERLIST + ',') > 0 ) c ON CHARINDEX(',' + CAST(c.privTypeId AS VARCHAR(5)) + ',',',' + a.PrivilegeOper + ',') > 0 WHERE typeCode='{0}' and isnull(isVisible,0)=0 order by a.orderid asc", DLLCoid, OperatorName); DataTable billDtFiled = gridBillInfo.SetColumns3(columsSql); //PubControl.SetColumns2(gridBillInfo, columsSql); gridBillInfo.gridView.OptionsBehavior.Editable = true; typeModel = SqlHelper.ExecuteDataSet("select * from P_systembilltype where typeCode='" + DLLCoid + "'").Tables[0].Rows[0]; string detailSql = typeModel["detailSql"] + ""; detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName); List listParm = PubClass.GetParamValue(typeModel["detailSql"] + ""); foreach (string s in listParm) detailSql = detailSql.Replace(s, billDocumentId); gridBillInfo.SetDataSource(detailSql); SetBillControlText(billModifyFields); SetBrpColumn(billDtFiled); } #region 切换模版相关 /// /// 设置brp模版列 /// public void SetBrpColumn(DataTable billDtFiled) { try { Control[] c = pl_right_main.Controls.Find("txt_brpid", true); if (c.Length > 0 && !string.IsNullOrEmpty(c[0].Text)) { string brpValue = c[0].Text; string sqlValue = string.Format("select * from P_pubrpsettab where ID='{0}'", brpValue); DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue); if (dtTable != null && dtTable.Rows.Count > 0) { DataRow row = dtTable.Rows[0]; int rowid = Convert.ToInt32(row["rowid"] + ""); // 隐藏所有列 foreach (DataRow item in billDtFiled.Rows) { string orderid = item["orderid"] + ""; string fieldname = item["fieldname"] + ""; GridColumn column = gridBillInfo.gridView.Columns[fieldname]; if (column != null) { column.Visible = Convert.ToInt32(orderid) > 100 ? true : false; } } // 重置单据明细列 for (int i = rowid; i >= 1; i--) { string defaultColName = "A" + i; foreach (DataRow item in billDtFiled.Rows) { string orderid = item["orderid"] + ""; string username = item["username"] + ""; string fieldname = item["fieldname"] + ""; GridColumn column = gridBillInfo.gridView.Columns[fieldname]; if (orderid == i + "") { column.Caption = row[defaultColName] + ""; column.Visible = true; break; } } } } } } catch (Exception ex) { } } #endregion #region 刷新单据 public void RefreshBill(object sender, string DJH) { //typeModel = SqlHelper.ExecuteDataSet("select * from P_systembilltype where typeCode='" + DLLCoid + "'").Tables[0].Rows[0]; int oldRowHandle = -1; string detailSql = typeModel["detailSql"] + ""; detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName); List listParm = PubClass.GetParamValue(typeModel["detailSql"] + ""); foreach (string s in listParm) detailSql = detailSql.Replace(s, billDocumentId); oldRowHandle = (gridBillInfo.gridControl.FocusedView as GridView).FocusedRowHandle; gridBillInfo.SetDataSource(detailSql); (gridBillInfo.gridControl.FocusedView as GridView).FocusedRowHandle = oldRowHandle; //刷新当前明细 XtraTabPage tagpage = tabDetailMain.SelectedTabPage; Control[] ctl = tagpage.Controls.Find(tagpage.Name.Replace("tab", "gce_"), true); if (ctl.Length < 1) return; if (ctl[0] == null) return; GridControlEx gce = ctl[0] as GridControlEx; string sql = gce.ConstSql; oldRowHandle = (gce.gridView as GridView).FocusedRowHandle; gce.SetDataSource(sql); (gce.gridView as GridView).FocusedRowHandle = oldRowHandle; } #endregion /// /// 查找单据控件 /// public void SetBillControlText(string billFields) { Control ctr = pl_right_main; //string billInfoSql = PubClass.ReqSqlParam(MasterSql, OperatorId, OperatorName); //List listPar = PubClass.GetParamValue(billInfoSql); //foreach (string item in listPar) //{ // billInfoSql = billInfoSql.Replace(item, billDocumentId); //} string billInfoSql = "select * from "+masterTable+" where "+column_prefix+"billdocument_id='"+billDocumentId+"'"; DataTable dtBillInfoMsg = SqlHelper.ExecuteDataSet(billInfoSql).Tables[0]; dtBillInfoRow = dtBillInfoMsg.Rows[0]; string rtagid = dtBillInfoRow[column_prefix + "Rtagid"].ToString(); SetBillStatus(dtBillInfoRow); foreach (DataRow row in dtFileds.Rows) { string filedName = "txt_" + row["fieldName"].ToString(); Control[] c = ctr.Controls.Find(filedName, true); DataColumnCollection dcc = dtBillInfoMsg.Columns; DataColumn dc = dcc[row["fieldName"].ToString()]; if ((dc != null) && (c != null) && (c.Length > 0)) { ControlModelTag tagModel = c[0].Tag as ControlModelTag; tagModel.isSetText = true; if (tagModel.fieldTypeId == 1) { LabelComboxEx cb = c[0] as LabelComboxEx; string value = dtBillInfoMsg.Rows[0][row["fieldName"] + ""] + ""; cb.getComboBox.DropDownStyle = ComboBoxStyle.DropDownList; if (!string.IsNullOrEmpty(value)) { cb.getComboBox.SelectedValue = value; } //cb.Enabled = false; } else if ((tagModel.fieldTypeId == 5) || (tagModel.fieldTypeId == 15)) { AutoSearcher autos = c[0] as AutoSearcher; string sql = PubClass.ReqSqlParam("select * from (" + autos.searcherPropertyCollector.QuerySQL + ") tab where " + autos.searcherPropertyCollector.FieldPropertyList[0].FieldName + "='" + dtBillInfoMsg.Rows[0][row["fieldName"].ToString()].ToString() + "'", OperatorId, OperatorName); sql = Regex.Replace(sql, "#[^##]+#", " 1=1 "); DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { //c[0].Text = dt.Rows[0][autos.searcherPropertyCollector.QueryField].ToString(); //te.SetValueSilent(mctext.dr[row["fieldName"].ToString()].ToString(), ""); autos.SetValueSilent(dt.Rows[0][autos.searcherPropertyCollector.FieldPropertyList[0].FieldName].ToString(), ""); //c[0].Enabled = false; } else { c[0].Text = string.Empty; //c[0].Enabled = false; } } else if (tagModel.fieldTypeId == ControlType.LabMultiSelectValue) { LabelLookUp lookup = c[0] as LabelLookUp; lookup.SetValueText(dtBillInfoMsg.Rows[0][row["fieldName"].ToString()].ToString()); } else { c[0].Text = dtBillInfoMsg.Rows[0][row["fieldName"].ToString()].ToString(); //c[0].Enabled = false; } //if (billFields.IndexOf(row["fieldName"].ToString() + ",", StringComparison.OrdinalIgnoreCase) != -1) // c[0].Enabled = true; int visible = Convert.ToInt32(row["visible"]); if (visible == 1) { c[0].Text = "****"; } if (c[0] is LabelTextEx) { (c[0] as LabelTextEx).GetTextBox.ReadOnly = true; } else if (c[0] is LabelAutoSearcherEx) { (c[0] as LabelAutoSearcherEx).GetAutoSearcher.ReadOnly = true; } else if (c[0] is AutoSearcher) { (c[0] as AutoSearcher).ReadOnly = true; } else if (c[0] is LabelMemoEdit) { (c[0] as LabelMemoEdit).getMemoEx.Properties.ReadOnly = true; } else c[0].Enabled = false; } } } #endregion #region 确定审核 /// /// 确定审核 /// /// /// private void btnOk_Click(object sender, EventArgs e) { //bool updateOk = UpdateForm(); //if (!updateOk) // return; //SqlParameter msg = new SqlParameter("@msg", SqlDbType.VarChar, 3000); //msg.Direction = ParameterDirection.Output; //SqlParameter[] param = //{ // new SqlParameter("@typeCode",SqlDbType.VarChar,10), // new SqlParameter("@stepCode",SqlDbType.Int,4), // new SqlParameter("@billDocumentId",SqlDbType.VarChar,20), // new SqlParameter("@operatorId",SqlDbType.Int,4), // new SqlParameter("@operatorName",SqlDbType.VarChar,20), // new SqlParameter("@auditAdvice",SqlDbType.VarChar,500), // new SqlParameter("@Direction",SqlDbType.Char,1), // msg //}; //param[0].Value = DLLCoid; //param[1].Value = stepCode; //param[2].Value = billDocumentId; //param[3].Value = OperatorId; //param[4].Value = OperatorName; //param[5].Value = txtRemark.Text; //param[6].Value = "F"; //param[7].Value = ""; //SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_BillAudit", "bill", param); //string result = msg.Value + ""; //if (result == "1") //{ // XtraMessageBox.Show("审核成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // this.DialogResult = DialogResult.OK; //} //else //{ // XtraMessageBox.Show("审核失败!" + result, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); //} } #endregion /// /// 添加表单到数据库 /// /// /// /// public bool UpdateForm() { //StringBuilder tagFiled = new StringBuilder(); StringBuilder tagValue = new StringBuilder(); StringBuilder tagSql = new StringBuilder(); string guid = Guid.NewGuid().ToString(); string billsql = string.Empty; string billitemsql = string.Empty; //单据头修改拼接 billsql = @"UPDATE " + masterTable + " SET {0} WHERE "+column_prefix+"Billdocument_Id='" + billDocumentId + "'"; foreach (DataRow row in dtBillInfoFiled.Rows) { string filedName = "txt_" + row["fieldName"].ToString(); Control[] c = pl_right_main.Controls.Find(filedName, true); if ((c.Length > 0) && (c[0].Enabled)) { ControlModelTag tagModel = c[0].Tag as ControlModelTag; if (tagModel.IsEmpt) { if (string.IsNullOrEmpty(c[0].Text)) { MessageBox.Show("请输入" + tagModel.TipMsg, "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } } if (tagModel.fieldTypeId == ControlType.LabDate || tagModel.fieldTypeId == ControlType.LabDateTime || tagModel.fieldTypeId == ControlType.LabDateTimeShort || tagModel.fieldTypeId == ControlType.LabTime || tagModel.fieldTypeId == ControlType.LabShortTime) { LabelDateEx labledataEx = c[0] as LabelDateEx; tagValue.Append(row["fieldName"] + "='" + labledataEx.GetDateTimePicker.Value.ToString("yyyy-MM-dd HH:mm:ss") + "',"); } else if (tagModel.fieldTypeId == ControlType.LabComboxValue) { LabelComboxEx comb = c[0] as LabelComboxEx; tagValue.Append(row["fieldName"] + "='" + comb.getComboBox.SelectedValue + "',"); } else if (tagModel.fieldTypeId == ControlType.LabAutoSeacherValue) { AutoSearcher autoSearch = c[0] as AutoSearcher; tagValue.Append(row["fieldName"] + "='" + autoSearch.ReturnValue + "',"); } else if (tagModel.fieldTypeId == ControlType.LabMultiSelectValue) { LabelLookUp lookup = c[0] as LabelLookUp; tagValue.Append(row["fieldName"] + "='" + lookup.ReturnValue + "',"); } else { tagValue.Append(row["fieldName"] + "='" + c[0].Text + "',"); } } } billsql = string.Format(billsql, tagValue.ToString().Trim(',')); if (tagValue.ToString().Trim() == "") billsql = ""; //MessageBox.Show(billsql); //单据头拼接结束 DataTable dtBillItem = gridBillInfo.gridControl.DataSource as DataTable; DataColumnCollection dccs = dtBillItem.Columns; foreach (DataRow row in dtBillItem.Rows) { if (row.RowState == DataRowState.Deleted) continue; billitemsql = @"insert into " + detailTable + "_temp" + "({0})values({1})"; StringBuilder tagFiled2 = new StringBuilder(); StringBuilder tagValue2 = new StringBuilder(); tagFiled2.Append("sysstr,"); tagValue2.Append("'" + guid + "',"); foreach (DataColumn item in dccs) { tagFiled2.Append(item.ColumnName + ","); string v = row[item.ColumnName] + ""; if (!string.IsNullOrEmpty(v)) { tagValue2.Append("'" + row[item.ColumnName] + "',"); } else if (v.IndexOf("guid", StringComparison.OrdinalIgnoreCase) != -1) { tagValue2.Append("'" + Guid.NewGuid() + "',"); } else { if (item.DataType.ToString().Contains("Decimal") || item.DataType.ToString().Contains("Int32") ) { tagValue2.Append("0,"); } else { tagValue2.Append("NULL,"); } } } billitemsql = string.Format(billitemsql, tagFiled2.ToString().Trim(','), tagValue2.ToString().Trim(',')); tagSql.Append(billitemsql + ";"); } SqlHelper.ExecuteNonQuery(tagSql.ToString()); SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@Sql",SqlDbType.VarChar,5000), new SqlParameter("@billdocument_id",SqlDbType.VarChar,500), new SqlParameter("@tmpstr",SqlDbType.VarChar,5000), new SqlParameter("@Operatorid",SqlDbType.Int), new SqlParameter("@Fbilltagid",SqlDbType.Int), new SqlParameter("@operateway",SqlDbType.Int), pMsg, returnValue }; param[0].Value = billsql; param[1].Value = billDocumentId; param[2].Value = guid; param[3].Value = OperatorId; param[4].Value = 2;// --1新增,2为修改,3为删除 param[5].Value = billSeq; param[6].Value = ""; DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "P_BillSavePr_3", "billSave", param); string msg = pMsg.Value.ToString(); int rVaule = Convert.ToInt32(returnValue.Value.ToString()); if (rVaule != 1) { XtraMessageBox.Show("操作失败[(" + rVaule + ")" + msg + "]", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return true; } #region 返回审核 /// /// 返回审核 /// /// /// private void btnReturn_Click(object sender, EventArgs e) { //SqlParameter msg = new SqlParameter("@msg", SqlDbType.VarChar, 3000); //msg.Direction = ParameterDirection.Output; //SqlParameter[] param = //{ // new SqlParameter("@typeCode",SqlDbType.VarChar,10), // new SqlParameter("@stepCode",SqlDbType.Int,4), // new SqlParameter("@billDocumentId",SqlDbType.VarChar,20), // new SqlParameter("@operatorId",SqlDbType.Int,4), // new SqlParameter("@operatorName",SqlDbType.VarChar,20), // new SqlParameter("@auditAdvice",SqlDbType.VarChar,500), // new SqlParameter("@Direction",SqlDbType.Char,1), // msg //}; //param[0].Value = DLLCoid; //param[1].Value = stepCode; //param[2].Value = billDocumentId; //param[3].Value = OperatorId; //param[4].Value = OperatorName; //param[5].Value = ""; //param[6].Value = "R"; //param[7].Value = ""; //SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_BillAudit", "bill", param); //string result = msg.Value + ""; //if (result == "1") //{ // XtraMessageBox.Show("反退成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // this.DialogResult = DialogResult.OK; //} //else //{ // XtraMessageBox.Show("反退失败!" + result, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //} } #endregion private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { e.Appearance.TextOptions.HAlignment = HorzAlignment.Center; if (e.Info.IsRowIndicator) { if (e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } } private void gridView1_RowStyle(object sender, RowStyleEventArgs e) { if (e.RowHandle >= 0) { DataRow row = gridView1.GetDataRow(e.RowHandle); if (row["sh"] + "" == "审") { e.Appearance.ForeColor = Color.Blue; } } } private void btnAtt_Click(object sender, EventArgs e) { string[] str = { FormText, OperatorId, OperatorName, Privilege, DLLCoid, billDocumentId, "1", DirId, "" }; IForm form = PubUtil.LoadDllForm2("Lskj.PhotoView.dll", str); form.SubForm.ShowDialog(); } #region 窗体关闭事件 /// /// 窗体关闭事件 /// /// protected override void OnClosed(EventArgs e) { //try //{ // if (PubUtil.ModuleForms != null && PubUtil.ModuleForms.ContainsKey(ModuleId)) // { // DllModule dm = PubUtil.ModuleForms[ModuleId]; // if (dm != null) // { // dm.ModuleForm = null; // dm.ModuleInPtr = IntPtr.Zero; // PubUtil.ModuleForms.Remove(ModuleId); // } // } //} //catch //{ //} } #endregion #region 打印 /// /// 打印 /// /// /// private void btnPrint_Click(object sender, EventArgs e) { string billNo = txt_Billdocument_Id.Text; if (!string.IsNullOrEmpty(billNo)) { string sql = PubClass.ReqSqlParam(MasterSql, OperatorId, OperatorName); List list = PubClass.GetParamValue(sql); foreach (string str in list) sql = sql.Replace(str, billNo); DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; DataRow row = null; if (dt != null && dt.Rows.Count > 0) { dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; row = dt.Rows[0]; string path = PubUtil.AbsolutelyPath + "lib/P_PubPrint.lsp"; billPrintSQL = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL, OperatorId, OperatorName)); billPrintSQL1 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL1, OperatorId, OperatorName)); billPrintSQL2 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL2, OperatorId, OperatorName)); PubUtil.LoadDelphiDll(path, path, billModuleFile, billPrintSQL, billPrintSQL1, Convert.ToInt32(billPrintType), billPrintSQL2); } else { DialogResult dr = XtraMessageBox.Show("你确定要保存单据后打印?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { dt = SqlHelper.ExecuteDataSet(sql).Tables[0]; row = dt.Rows[0]; string path = PubUtil.AbsolutelyPath + "lib/P_PubPrint.lsp"; billPrintSQL = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL, OperatorId, OperatorName)); billPrintSQL1 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL1, OperatorId, OperatorName)); billPrintSQL2 = PubClass.ReqSql(row, PubClass.ReqSqlParam(billPrintSQL2, OperatorId, OperatorName)); PubUtil.LoadDelphiDll(path, path, billModuleFile, billPrintSQL, billPrintSQL1, Convert.ToInt32(billPrintType), billPrintSQL2); } } } } #endregion private void OnMyPaint(PaintEventArgs e, object sender) { base.OnPaint(e); GraphicsText graphicsText = new GraphicsText(); graphicsText.Graphics = e.Graphics; // 绘制围绕点旋转的文本 int width = 120; int height = 32; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; if (_text != "") { graphicsText.DrawString(_text, _font, _brush, new PointF(((sender as Control).Width - width) / 2, ((sender as Control).Height - height) / 2), format, _angle); int x = ((sender as Control).Width - width) / 2; int y = ((sender as Control).Height - height) / 2; e.Graphics.TranslateTransform(x, y); e.Graphics.RotateTransform(_angle); e.Graphics.DrawRectangle(_pen, new Rectangle(0 - width / 2, 0 - height / 2 - 3, width, height)); } e.Graphics.ResetTransform(); if (_textPrint != "") { graphicsText.DrawString(_textPrint, _font1, _brush, new PointF(((sender as Control).Width - width) / 2, ((sender as Control).Height - 90) / 2 -40), format, _angle); //graphicsText.DrawString(_textPrint, _font, _brush, new PointF(50, 21), format, _angle); int x = ((sender as Control).Width - width) / 2; int y = ((sender as Control).Height - 90) / 2 -40; e.Graphics.TranslateTransform(x, y); e.Graphics.RotateTransform(_angle); e.Graphics.DrawRectangle(_pen, new Rectangle(0 - width / 2, 0 - height / 2 - 3, width, height)); } e.Graphics.ResetTransform(); if (_text_collect != "") { graphicsText.DrawString(_text_collect, _font, _brush, new PointF(((sender as Control).Width - width) / 2, ((sender as Control).Height - 180) / 2 + 100), format, _angle); //graphicsText.DrawString(_textPrint, _font, _brush, new PointF(50, 21), format, _angle); int x = ((sender as Control).Width - width) / 2; int y = ((sender as Control).Height - 180) / 2 + 100; e.Graphics.TranslateTransform(x, y); e.Graphics.RotateTransform(_angle); e.Graphics.DrawRectangle(_pen, new Rectangle(0 - width / 2, 0 - height / 2 - 3, width, height)); } } private void gridBillInfo_Paint(object sender, PaintEventArgs e) { OnMyPaint(e,sender); } #region private void SetBillStatus(DataRow datarow) { if ((datarow.Table.Columns.Contains(column_prefix + "waste_flag")) && ((datarow[column_prefix + "waste_flag"] + "" == "1") || ((datarow[column_prefix + "waste_flag"] + "").ToLower() == "true"))) _text = "已作废"; else if ((datarow.Table.Columns.Contains(column_prefix + "cancelflag")) && ((datarow[column_prefix + "cancelflag"] + "" == "1") || ((datarow[column_prefix + "cancelflag"] + "").ToLower() == "true"))) _text = "已关闭"; else if ((datarow[column_prefix + "stepover"] + "" == "1") || ((datarow[column_prefix + "stepover"] + "").ToLower() == "true")) { _text = "已终审"; if (datarow.Table.Columns.Contains(column_prefix + "collectMoneyFlag")) _text = "已过账"; } else if ((datarow[column_prefix + "ban"] + "" == "1") || ((datarow[column_prefix + "ban"] + "").ToLower() == "true")) _text = "在 审"; else if ((datarow[column_prefix + "affirmer"] + "" != "0") && (datarow[column_prefix + "affirmer"] + "" != "")) _text = "待 审"; else _text = "草 稿"; _textPrint = ""; if (datarow.Table.Columns.Contains(column_prefix + "printCount")) _textPrint = "打印" + (datarow[column_prefix + "printCount"] + "" == "" ? "0" : datarow[column_prefix + "printCount"] + "") + "次"; _text_collect = ""; if (datarow.Table.Columns.Contains(column_prefix + "collectMoneyFlag")) { if (datarow[column_prefix + "collectMoneyFlag"] + "" == "1") _text_collect = "已收款"; } } #endregion private void btn_Return_Click(object sender, EventArgs e) { //bool updateOk = UpdateForm(); //if (!updateOk) // return; int ret = ExecuteBackSelect(dtBillInfoRow); if (ret == -9) return; if (XtraMessageBox.Show("确认审核不通过并反退该单据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { #region 记录本次推送人员,审核成功后清除对应人员消息 string beforemenuname = string.Empty, beforeusers = string.Empty; int beforeid = 0; try { string sqlValue = string.Format("select operators,typeName menuname,'2'+CAST(b.id as varchar(10)) id from wms_billflowOper a,p_systembilltype b where a.modid=b.typeCode and keyvalue='{0}' and stepcode='{1}' and a.stepover=0", billDocumentId, stepCode); DataTable dtTable = SqlHelper.ExecuteDataSet(sqlValue).Tables[0]; if (dtTable.Rows.Count > 0) { beforemenuname = dtTable.Rows[0]["menuname"] + ""; beforeusers = dtTable.Rows[0]["operators"] + ""; beforeid = Convert.ToInt32(dtTable.Rows[0]["id"] + ""); } } catch (Exception) { } #endregion SqlParameter msg = new SqlParameter("@msg", SqlDbType.VarChar, 3000); msg.Direction = ParameterDirection.Output; SqlParameter[] param = { new SqlParameter("@typeCode",SqlDbType.VarChar,10), new SqlParameter("@stepCode",SqlDbType.Int,4), new SqlParameter("@billDocumentId",SqlDbType.VarChar,20), new SqlParameter("@operatorId",SqlDbType.Int,4), new SqlParameter("@operatorName",SqlDbType.VarChar,20), new SqlParameter("@auditAdvice",SqlDbType.VarChar,500), new SqlParameter("@Direction",SqlDbType.Char,1), msg, new SqlParameter("@backStepCode",SqlDbType.Int,4) }; param[0].Value = DLLCoid; param[1].Value = stepCode; param[2].Value = billDocumentId; param[3].Value = OperatorId; param[4].Value = OperatorName; param[5].Value = AuditAdvice; param[6].Value = "R"; param[7].Value = ""; param[8].Value = ret; SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_BillAudit", "bill", param); string result = msg.Value + ""; if (result == "1") { XtraMessageBox.Show("反退成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // 推送消息 //PushHelper.push_bill_oper_message(billDocumentId, stepCode, DLLCoid, beforeusers, beforemenuname, beforeid); PushHelper push = new PushHelper(billDocumentId, stepCode, DLLCoid, beforeusers, beforemenuname, beforeid); push.push_bill_oper_message(); this.DialogResult = DialogResult.OK; } else { XtraMessageBox.Show("反退失败!" + result, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } private int ExecuteBackSelect(DataRow row) { if (row == null) { MessageBox.Show("没有找到需要反审核的单据"); return -9; } //判断返退选择标记 if (BackSelected == "0") return -1; //第一步直接返退到提交人 if (row[column_prefix + "stepCode"].ToString() == "100") return 0; int billtype = Convert.ToInt32(row[column_prefix + "billtype"].ToString()); frmBackSelect frmSel = new frmBackSelect(DLLCoid, Convert.ToInt32(row[column_prefix + "stepCode"].ToString()), billtype, billDocumentId, masterTable, column_prefix); DialogResult dlg = frmSel.ShowDialog(); if (dlg != DialogResult.OK) return -9; AuditAdvice = frmSel.ComfirmMsg; return frmSel.SelectStepCode; } } }