using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.Common; using CommonLib; using CommonLib.utils; using DevExpress.XtraGrid.Columns; using ExcelPlus; using System.Data.SqlClient; using Lskj.MyControl; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraEditors; using DevExpress.XtraTab; namespace Lskj.PubModuleDetailBrp { public partial class Panel_TabPage : UserControl { //模块ID public string DLLCoid { get; set; } //管理员Id public string OperatorId { get; set; } //管理员名称 public string OperatorName { get; set; } //权限 public string Privilege { get; set; } //窗体标题 public string FormText { get; set; } //对象Id public string objectId { get; set; } //对象值 public string objectValue { get; set; } public string dllSql { get; set; } public string autoRefresh { get; set; } /// /// 是否报表 /// public bool HasReport { get; set; } private string addCond; // 添加条件 private string deleteCond; // 删除条件 private string modifyCond; // 修改条件 private string printCond=string.Empty; private string exportCond=string.Empty; private string oldSql = string.Empty; bool addEnable = false; bool deleteEnable = false; bool importEnable = false; bool exportEnable = false; bool searchEnable = false; /// /// 必须录入字段 /// private DataRow[] nullableFields; private string mParmaryKey; //主表数据 private DataTable dtSystemDlltab; private DataTable dtSum; //主键数据 private DataTable idFiledKey; private bool needModified; private bool gridEdited = false; private int mEnterOrder; // 0.默认列跳转,1为行跳转 /// /// 条件颜色 /// private DataTable dtSysColorList; /// /// DbDataAdapter /// private SqlDataAdapter da; /// /// 操作Dataset /// private DataSet ds = new DataSet(); public string pageText; public int parentPriv; public DataTable dtColumns = new DataTable(); public Panel_TabPage() { InitializeComponent(); } /// /// 初始化数据 /// /// protected override void OnLoad(EventArgs e) { RefreshTabPageTitle(); nullableFields = dtColumns.Rows.OfType().Where(x => x["tagid"] + "" == "1").ToArray(); dtSystemDlltab = CommonLib.SqlHelper.ExecuteDataSet("select * from P_systemDlltab where DLLCoid='" + DLLCoid + "'").Tables[0]; if (dtSystemDlltab != null && dtSystemDlltab.Rows.Count > 0) { addCond = dtSystemDlltab.Rows[0]["addCond"] + ""; deleteCond = dtSystemDlltab.Rows[0]["deleteCond"] + ""; modifyCond = dtSystemDlltab.Rows[0]["modifyCond"].ToString(); needModified = dtSystemDlltab.Rows[0]["modifyEnable"].ToString() == "1"; gridEdited = (string.IsNullOrEmpty(dtSystemDlltab.Rows[0]["selfEdit"] + "") || dtSystemDlltab.Rows[0]["selfEdit"] + "" == "0" || dtSystemDlltab.Rows[0]["selfEdit"] + "" == "False") ? false : true; gridList.gridView.OptionsBehavior.Editable = gridEdited; if (dtSystemDlltab.Columns.Contains("exportCond")) exportCond = dtSystemDlltab.Rows[0]["exportCond"].ToString(); if (dtSystemDlltab.Columns.Contains("printCond")) printCond = dtSystemDlltab.Rows[0]["printCond"].ToString(); if (dtSystemDlltab.Columns.Contains("EnterOrder")) mEnterOrder = string.IsNullOrEmpty(dtSystemDlltab.Rows[0]["EnterOrder"] + "") ? 0 : Convert.ToInt32(dtSystemDlltab.Rows[0]["EnterOrder"] + ""); addEnable = dtSystemDlltab.Rows[0]["addEnable"] + "" == "1"; deleteEnable = dtSystemDlltab.Rows[0]["deleteEnable"] + "" == "1"; importEnable = dtSystemDlltab.Rows[0]["importEnable"] + "" == "1"; exportEnable = dtSystemDlltab.Rows[0]["exportEnable"] + "" == "1"; searchEnable = dtSystemDlltab.Rows[0]["searchEnable"] + "" == "1"; btnAdd.Enabled = addEnable; btnDelete.Enabled = deleteEnable; btnImport.Enabled = importEnable; btnExport.Enabled = exportEnable; btnCondSearch.Enabled = searchEnable; btnUpdate.Enabled = needModified; btnSave.Enabled = needModified; //gridList.gridView.OptionsBehavior.Editable = true; if (parentPriv != 1) { gridList.gridView.OptionsBehavior.Editable = false; addCond = addCond.Trim() == "" ? " 1<>1 " : addCond + " and 1<>1"; modifyCond = modifyCond.Trim() == "" ? "1<>1" : modifyCond + " and 1<>1"; deleteCond = deleteCond.Trim() == "" ? "1<>1" : deleteCond + " and 1<>1"; btnImport.Visible = false; btnAdd.Visible = false; btnSave.Visible = false; btnDelete.Visible = false; btnUpdate.Visible = false; btnImport.Enabled = false; btnAdd.Enabled = false; btnSave.Enabled = false; btnDelete.Enabled = false; btnUpdate.Enabled = false; } setButtonStatus(); } // 当前标签为报表 if (HasReport) { btnAdd.Visible = btnDelete.Visible = btnImport.Visible = btnUpdate.Visible = btnSave.Visible = false; } idFiledKey = SqlHelper.ExecuteDataSet("select top 1 * from P_systemwordbooktab where tab='" + DLLCoid + "' order by orderid").Tables[0]; GridMenu gm =null; mParmaryKey = idFiledKey.Rows[0]["fieldname"] + ""; if (parentPriv == 1) { gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", gridList.gridControl); gm.DirId = dtSystemDlltab.Rows[0]["dirid"] + ""; gm.filedKey = idFiledKey.Rows[0]["fieldname"].ToString(); gm.BindGridMenuWQ(DLLCoid); gm.OnGridMenuClickRefreshData += new EventHandler(gm_OnGridMenuClickRefreshData); } gridList.gridControl.DoubleClick += new EventHandler(gridControl_DoubleClick); gridList.gridView.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(gridView_SelectionChanged); dtSysColorList = SqlHelper.ExecuteDataSet("select * from P_systemwordbookcolor where tab='" + DLLCoid + "' and isnull(useflag,0)=0 order by orderid").Tables[0]; gridList.gridView.RowStyle += new RowStyleEventHandler(gridView_RowStyle); DataTable cbSearchFiled = SqlHelper.ExecuteDataSet("select * from P_systemwordbooktab where tab='" + DLLCoid + "' and ifSearch =0 and isnull(username1,'')<>''").Tables[0]; //查询统计列 string isSumSql = "select * from p_systemwordbooktab where tab='" + DLLCoid + "' and isnull(vislble,0)=0 and isnull(calcExpr,'')<>''order by calcOrder asc"; dtSum = SqlHelper.ExecuteDataSet(isSumSql).Tables[0]; gridList.SumFieldsTable = dtSum; //加载筛选框 cbField.DataSource = cbSearchFiled; cbField.DisplayMember = "username1"; cbField.ValueMember = "fieldname"; if (autoRefresh == "1") { InitData(gridList.Sql); } } /// /// 执行右键菜单后刷新表格数据 /// /// /// private void gm_OnGridMenuClickRefreshData(object sender, EventArgs e) { InitData(gridList.Sql); } #region 行颜色 private void gridView_RowStyle(object sender, RowStyleEventArgs e) { if (e.RowHandle >= 0) { DataRow row = gridList.gridView.GetDataRow(e.RowHandle); string cond = string.Empty; string color = string.Empty; string forecolor = string.Empty; foreach (DataRow dr in dtSysColorList.Rows) { //string[] strSplit = dr["condition"].ToString().Split('='); //if (strSplit.Length >= 2) //{ // string filed = strSplit[0].Replace("{", "").Replace("}", ""); // string value = strSplit[1]; // if (value == row[filed] + "") // { // System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(dr["backcolor"].ToString()); // System.Drawing.Color foreColor = System.Drawing.ColorTranslator.FromHtml(dr["forcecolor"].ToString()); // e.Appearance.BackColor = color; // e.Appearance.ForeColor = foreColor; // } //} 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 = 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; } FontStyle fst = new FontStyle(); if (dr["ifBold"].ToString() == "1") { fst = fst | FontStyle.Bold; } if (dr["ifItalic"].ToString() == "1") { fst = fst | FontStyle.Italic; } if (dr["ifStrickOut"].ToString() == "1") { fst = fst | FontStyle.Strikeout; } if (dr["ifUnderLine"].ToString() == "1") { fst = fst | FontStyle.Underline; } e.Appearance.Font = new Font(e.Appearance.Font, fst); } } } } #endregion private void gridView_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { /* int[] rows = gridList.gridView.GetSelectedRows(); if (rows != null && rows.Length > 0) { DataRow row = gridList.gridView.GetDataRow(rows[0]); bool isAdd = true; bool isDelete = true; bool isUpdate = true; // 添加权限 if (!string.IsNullOrEmpty(addCond)) { string tempCond = PubClass.ReqSqlWhere(row, PubClass.ReqSqlParam(addCond, OperatorId, OperatorName)); isAdd = Convert.ToBoolean(Evaluator.Eval(tempCond)); } // 删除权限 if (!string.IsNullOrEmpty(deleteCond)) { string tempCond = PubClass.ReqSqlWhere(row, PubClass.ReqSqlParam(deleteCond, OperatorId, OperatorName)); isDelete = Convert.ToBoolean(Evaluator.Eval(tempCond)); } // 修改、保存权限 if (!string.IsNullOrEmpty(modifyCond)) { string tempCond = PubClass.ReqSqlWhere(row, PubClass.ReqSqlParam(modifyCond, OperatorId, OperatorName)); isUpdate = Convert.ToBoolean(Evaluator.Eval(tempCond)); gridList.gridView.OptionsBehavior.Editable = isUpdate; } btnAdd.Enabled = isAdd; btnDelete.Enabled = isDelete; btnUpdate.Enabled = btnSave.Enabled = isUpdate; } */ setButtonStatus(); } private void setButtonStatus() { bool isAdd = true; bool isDelete = true; bool isUpdate = true; bool isExport = true; bool isPrint = true; // 添加权限 if (!string.IsNullOrEmpty(addCond)) { string tempCond = PubClass.SqlToCode( PubClass.ReqSqlParam(addCond, OperatorId, OperatorName)); isAdd = Convert.ToBoolean(Evaluator.Eval(tempCond)) && addEnable; } if (!string.IsNullOrEmpty(exportCond)) { string tempCond = PubClass.SqlToCode(PubClass.ReqSqlParam(exportCond, OperatorId, OperatorName)); isExport = Convert.ToBoolean(Evaluator.Eval(tempCond)) && exportEnable; } if (!string.IsNullOrEmpty(printCond)) { string tempCond = PubClass.SqlToCode(PubClass.ReqSqlParam(printCond, OperatorId, OperatorName)); isPrint = Convert.ToBoolean(Evaluator.Eval(tempCond)); } int[] rows = gridList.gridView.GetSelectedRows(); if (rows != null && rows.Length > 0) { DataRow row = gridList.gridView.GetDataRow(rows[0]); // 删除权限 if (!string.IsNullOrEmpty(deleteCond)) { string tempCond = PubClass.ReqSqlWhere(row, PubClass.ReqSqlParam(deleteCond, OperatorId, OperatorName)); isDelete = Convert.ToBoolean(Evaluator.Eval(tempCond)) && deleteEnable; } // 修改、保存权限 if (!string.IsNullOrEmpty(modifyCond)) { string tempCond = PubClass.ReqSqlWhere(row, PubClass.ReqSqlParam(modifyCond, OperatorId, OperatorName)); //MessageBox.Show(tempCond); isUpdate = Convert.ToBoolean(Evaluator.Eval(tempCond)) && needModified; gridList.gridView.OptionsBehavior.Editable = isUpdate && gridEdited ; } btnAdd.Enabled = isAdd; btnDelete.Enabled = isDelete; btnUpdate.Enabled = btnSave.Enabled = isUpdate; } btnAdd.Enabled = isAdd; btnDelete.Enabled = isDelete; btnUpdate.Enabled = btnSave.Enabled = isUpdate; btnImport.Enabled = btnAdd.Enabled; btnExport.Enabled = isExport; btnPrint.Enabled = isPrint; } private void gridControl_DoubleClick(object sender, EventArgs e) { if (!string.IsNullOrEmpty(dtSystemDlltab.Rows[0]["AddDllName"] + "")) UpdateModel(); } private void btnPrint_Click(object sender, EventArgs e) { PubClass.Preview(gridList.gridControl); } private void btnDelete_Click(object sender, EventArgs e) { int[] rowid = gridList.gridView.GetSelectedRows(); if (rowid.Length == 0) { MessageBox.Show("没有选择要删除数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } else { if (MessageBox.Show("您确定要删除选中记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string ids = string.Empty; foreach (int rid in rowid) { DataRow dr = gridList.gridView.GetDataRow(rid); //判断删除条件是否符合 Boolean canDelete = string.IsNullOrEmpty(deleteCond); string tempCond = deleteCond; if (!canDelete) { tempCond = PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName); tempCond = PubClass.ReqSqlWhere(dr, tempCond); canDelete = Convert.ToBoolean(Evaluator.Eval(tempCond)); } if (canDelete) ids += "'" + dr[idFiledKey.Rows[0]["fieldname"] + ""] + "',"; } if (ids != string.Empty) { string sql = "delete from " + dtSystemDlltab.Rows[0]["SQLDT1"] + " where " + idFiledKey.Rows[0]["fieldname"] + " in(" + ids.Trim(',') + ")"; SqlHelper.ExecuteNonQuery(sql); InitData(gridList.Sql); MessageBox.Show("记录删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("没有符合删除条件的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(objectValue)) { XtraMessageBox.Show("请选择条数据后再添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (!string.IsNullOrEmpty(dtSystemDlltab.Rows[0]["AddDllName"] + "")) { string[] args = { FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", "", "", objectId, objectValue, dllSql }; IForm form = PubUtil.LoadDllForm(dtSystemDlltab.Rows[0]["AddDllName"] + "", args); DialogResult result = form.SubForm.ShowDialog(); InitData(gridList.Sql); RefreshTabPageTitle(); } else { AddRow(gridList.gridView); } } } /// /// 添加行 /// /// protected void AddRow(DevExpress.XtraGrid.Views.Grid.GridView view) { int prevDataRowIndex = view.GetFocusedDataSourceRowIndex(); view.AddNewRow(); DataTable dt = null; if (!string.IsNullOrEmpty(dllSql) && dllSql.Contains("select")) { dt = SqlHelper.ExecuteDataSet(dllSql).Tables[0]; } //默认值 foreach (GridColumn item in view.Columns) { if (item.Tag != null) { MyTagModel cmt = item.Tag as MyTagModel; if (cmt != null) { string defaultValue = PubClass.GetDefaultValue(cmt.DefaultValue.ToString(), OperatorId, OperatorName); if (item.FieldName.ToUpper().Equals(objectId.ToUpper())) { view.SetRowCellValue(view.FocusedRowHandle, item, objectValue); } else if (dt != null && dt.Rows.Count > 0) { foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName.ToUpper() == item.FieldName.ToUpper()) { view.SetRowCellValue(view.FocusedRowHandle, item, dt.Rows[0][dc.ColumnName]); } } } else { if (!string.IsNullOrEmpty(defaultValue)) { view.SetRowCellValue(view.FocusedRowHandle, item, defaultValue); } } } } } } /// /// 导出Excel /// /// /// private void btnExport_Click(object sender, EventArgs e) { PubClass.SaveXls(gridList.gridControl); } /// /// 导入Excel /// /// /// private void btnImport_Click(object sender, EventArgs e) { string columnPrefix = PubClass.GetColumnPrefix(dtSystemDlltab.Rows[0]["SQLDT1"].ToString()); frmImport frm = new frmImport(gridList, dtSystemDlltab.Rows[0]["SQLDT1"].ToString(), objectId, objectValue, OperatorId, OperatorName, columnPrefix, objectId, objectValue); DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { InitData(oldSql); RefreshTabPageTitle(); } } public bool UpdateModel() { if (dtSystemDlltab.Rows[0]["AddDllName"] + "" == "") { return false; } int[] rows = gridList.gridView.GetSelectedRows(); if (rows.Length > 0) { DataRow dr = gridList.gridView.GetDataRow(rows[0]); //判断修改条件是否符合 Boolean canModify = string.IsNullOrEmpty(modifyCond); if (needModified) { string tempCond = modifyCond; if (!canModify) { tempCond = PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName); tempCond = PubClass.ReqSqlWhere(dr, tempCond); canModify = Convert.ToBoolean(Evaluator.Eval(tempCond)); } } else { canModify = false; } canModify = canModify && (!Privilege.Equals("1")); string productId = dr[idFiledKey.Rows[0]["fieldname"] + ""].ToString(); string[] args = { FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", Convert.ToInt32(!canModify).ToString(), productId, "", "", "", dllSql }; IForm form = PubUtil.LoadDllForm(dtSystemDlltab.Rows[0]["AddDllName"] + "", args); form.SubForm.ShowDialog(); } InitData(gridList.Sql); RefreshTabPageTitle(); return true; } private void btnUpdate_Click(object sender, EventArgs e) { UpdateModel(); } private void btnSave_Click(object sender, EventArgs e) { try { da.Update(ds); (gridList.gridControl.DataSource as DataTable).AcceptChanges(); } catch (InvalidOperationException ioe) { // 多表保存失败 gridSave(); return; } catch (DBConcurrencyException dce) { // 并发异常 XtraMessageBox.Show("数据已更新,请刷新后重试."); return; } catch (Exception ex) { if (ex.Message.IndexOf("ix", StringComparison.OrdinalIgnoreCase) != -1) { XtraMessageBox.Show("系统检测到录入信息重复,请检查", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { XtraMessageBox.Show(ex.Message); return; } } XtraMessageBox.Show("修改成功"); } /// /// 表格必须录入验证 /// /// private bool gridRequired() { DataTable dtBillItem = gridList.gridControl.DataSource as DataTable; DataColumnCollection dtBillRow = dtBillItem.Columns; GridView gridView = gridList.gridView; GridColumnCollection gridColumns = gridView.Columns; foreach (DataRow drGrid in dtBillItem.Rows) { foreach (DataRow dr in nullableFields) { string fieldName = dr["fieldName"] + ""; string fieldText = dr["username1"] + ""; if (string.IsNullOrEmpty(drGrid[fieldName] + "")) { XtraMessageBox.Show(string.Format("[{0}] 不能为空", fieldText)); gridView.Focus(); gridView.FocusedRowHandle = dtBillItem.Rows.IndexOf(drGrid); gridView.FocusedColumn = gridColumns[fieldName]; gridView.SelectCell(gridView.FocusedRowHandle, gridColumns[fieldName]); gridView.ShowEditorByMouse(); return false; } } } return true; } /// /// 多表表格修改 /// private void gridSave() { try { if (dtSystemDlltab == null || dtSystemDlltab.Rows.Count == 0) return; string tabName = dtSystemDlltab.Rows[0]["SQLDT1"] + ""; if (string.IsNullOrEmpty(tabName)) { XtraMessageBox.Show("检测到未设置表名"); return; } List mList = new List(); StringBuilder mBuilder = new StringBuilder(); DataColumnCollection columns = SqlHelper.ExecuteDataTable(string.Format("select * from {0} where 1<>1", tabName)).Columns; DataTable dtTable = gridList.gridControl.DataSource as DataTable; List modifiedRows = dtTable.Rows.Cast().Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added).ToList(); foreach (DataRow row in modifiedRows) { string updateSql = "update {0} set {1} where {2}='{3}';"; string insertSql = "insert into {0}({1}) values({2});"; string updateFields = string.Empty; string insertFields = string.Empty; string insertValues = string.Empty; foreach (DataColumn col in columns) { // 区分大小写匹配列 DataRow hasContainRow = dtColumns.Rows.Cast().FirstOrDefault(x => x["fieldname"] + "" == col.ColumnName); if (hasContainRow != null && col.ColumnName != mParmaryKey) { if (row.RowState == DataRowState.Modified) { // 禁编列不更新 if (hasContainRow["edit"] + "" == "0") { updateFields += string.Format("{0}='{1}',", col.ColumnName, row[col.ColumnName]); } } else if (row.RowState == DataRowState.Added) { insertFields += col.ColumnName + ","; insertValues += "'" + row[col.ColumnName] + "',"; } } } updateFields = updateFields.TrimEnd(','); insertFields = insertFields.TrimEnd(','); insertValues = insertValues.TrimEnd(','); if (!string.IsNullOrEmpty(updateFields)) { updateSql = string.Format(updateSql, tabName, updateFields, mParmaryKey, row[mParmaryKey]); mList.Add(updateSql); } if (!string.IsNullOrEmpty(insertFields)) { insertSql = string.Format(insertSql, tabName, insertFields, insertValues); mList.Add(insertSql); } } // 由于数据sql长度限制,每次只保存10条数据 int resultCount = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < mList.Count; i++) { if (i == mList.Count - 1 || (i != 0 && i % 10 == 0)) { if (i == mList.Count - 1) mBuilder.Append(mList[i]); 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("@baseSql",SqlDbType.VarChar,8000), new SqlParameter("@saveType",SqlDbType.Int), new SqlParameter("@modid",SqlDbType.VarChar,20), new SqlParameter("@tablename",SqlDbType.VarChar,50), new SqlParameter("@keyfield",SqlDbType.VarChar,50), new SqlParameter("@keyvalue",SqlDbType.VarChar,50), new SqlParameter("@Operatorid",SqlDbType.Int), new SqlParameter("@operatorname",SqlDbType.VarChar,50), pMsg, returnValue }; param[0].Value = mBuilder.ToString(); param[1].Value = 8;// --8新增保存,9修改保存,10 删除条码 param[2].Value = DLLCoid; param[3].Value = tabName; param[4].Value = mParmaryKey; param[5].Value = ""; param[6].Value = OperatorId; param[7].Value = OperatorName; DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "P_BaseSave", "baseSave", param); string rMsg = pMsg.Value.ToString(); resultCount += Convert.ToInt32(returnValue.Value.ToString()); if (returnValue.Value + "" != "1") { XtraMessageBox.Show("保存失败.错误原因:" + rMsg); break; } mBuilder.Clear(); } mBuilder.Append(mList[i]); } if (resultCount > 0) { if (resultCount == mList.Count) { (gridList.gridControl.DataSource as DataTable).AcceptChanges(); XtraMessageBox.Show("保存成功"); } } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } } /// /// 初始化数据 /// /// public void InitData(string sql) { this.oldSql = sql; int oldRowHandle = (gridList.gridView).FocusedRowHandle; da = SqlHelper.ExecuteAdapter(CommandType.Text, sql); if (ds != null && ds.Tables.Count > 0) ds.Clear(); da.Fill(ds); SqlCommandBuilder cb = new SqlCommandBuilder(da); gridList.gridControl.DataSource = ds.Tables[0]; (gridList.gridView).ClearSelection(); (gridList.gridView).FocusedRowHandle = oldRowHandle; (gridList.gridView).SelectRow(oldRowHandle); setButtonStatus(); } /// /// 刷新标题 /// private void RefreshTabPageTitle() { try { (this.Parent.Parent as XtraTabControl).SelectedTabPage.Text = FormText + "(" + ds.Tables[0].Rows.Count + ")"; } catch (Exception) { } } private void btnCondSearch_Click(object sender, EventArgs e) { InitData(gridList.Sql); } } }