1033 lines
44 KiB
C#
1033 lines
44 KiB
C#
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.PubModuleDetail
|
|
{
|
|
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; }
|
|
/// <summary>
|
|
/// 是否报表
|
|
/// </summary>
|
|
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;
|
|
|
|
private DevExpress.XtraTreeList.Nodes.TreeListNode selectNode;
|
|
|
|
|
|
bool addEnable = false;
|
|
bool deleteEnable = false;
|
|
bool importEnable = false;
|
|
bool exportEnable = false;
|
|
bool searchEnable = false;
|
|
|
|
/// <summary>
|
|
/// 必须录入字段
|
|
/// </summary>
|
|
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为行跳转
|
|
/// <summary>
|
|
/// 条件颜色
|
|
/// </summary>
|
|
private DataTable dtSysColorList;
|
|
public EventHandler OnSaveAfter;
|
|
|
|
/// <summary>
|
|
/// 树表格配置
|
|
/// </summary>
|
|
//public bool TreeGridState = false;
|
|
/// <summary>
|
|
/// DbDataAdapter
|
|
/// </summary>
|
|
private SqlDataAdapter da;
|
|
/// <summary>
|
|
/// 操作Dataset
|
|
/// </summary>
|
|
private DataSet ds = new DataSet();
|
|
public string pageText;
|
|
public int parentPriv;
|
|
public DataTable dtColumns = new DataTable();
|
|
public Panel_TabPage()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化数据
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
|
|
//if (TreeGridState) this.treeList.Visible = true;
|
|
RefreshTabPageTitle();
|
|
nullableFields = dtColumns.Rows.OfType<DataRow>().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);
|
|
}
|
|
}
|
|
public void InitMenu()
|
|
{
|
|
GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", treeList);
|
|
gm.BindGridMenuTreeList(DLLCoid);
|
|
gm.OnGridMenuClickRefreshData += new EventHandler(gm_OnGridMenuClickRefreshData);
|
|
}
|
|
public void InitTreeGrid(string keyFieldName, string parentFieldName)
|
|
{
|
|
treeList.KeyFieldName = "tree_id";//主键名称
|
|
treeList.ParentFieldName = "tree_pid";//父级ID
|
|
}
|
|
/// <summary>
|
|
/// 设置树表格列
|
|
/// </summary>
|
|
/// <param name="dtFileds"></param>
|
|
public void SetTreeColumn(DataTable dtFileds)
|
|
{
|
|
for (int i = 0; i < dtFileds.Rows.Count; i++)
|
|
{
|
|
DataRow row = dtFileds.Rows[i];
|
|
DevExpress.XtraTreeList.Columns.TreeListColumn gridColumn = new DevExpress.XtraTreeList.Columns.TreeListColumn();
|
|
gridColumn.FieldName = row["fieldname"].ToString();
|
|
gridColumn.Name = row["fieldname"].ToString();
|
|
gridColumn.VisibleIndex = i;
|
|
gridColumn.Caption = row["username1"].ToString();
|
|
gridColumn.Width = Convert.ToInt32(row["width"]);
|
|
gridColumn.Visible = true;
|
|
gridColumn.Visible = ((Convert.ToInt32(row["width"]) > 0));
|
|
|
|
gridColumn.OptionsFilter.FilterPopupMode = DevExpress.XtraTreeList.FilterPopupMode.CheckedList;
|
|
gridColumn.OptionsColumn.AllowEdit = false;
|
|
gridColumn.OptionsColumn.ReadOnly = false;
|
|
|
|
string dataFormat = row["DataFormat"] + "";
|
|
|
|
Lskj.PubUtils.CommonUtils.DataFormat(gridColumn, row["DataFormat"] + "", 7); // 单据来源明细没有定义列类型,默认按照数字方式格式化
|
|
DataColumn dc = dtFileds.Columns["Accuracy"];
|
|
if (dc != null)
|
|
{
|
|
string Accuracy = dtFileds.Rows[i]["Accuracy"] + "";
|
|
if (!string.IsNullOrEmpty(Accuracy) && Accuracy != "0")
|
|
{
|
|
gridColumn.Format.FormatType = DevExpress.Utils.FormatType.Numeric;
|
|
gridColumn.Format.FormatString = "F2";
|
|
}
|
|
}
|
|
|
|
DataColumn dcIsSum = dtFileds.Columns["isSum"];
|
|
if (dcIsSum != null)
|
|
{
|
|
if (!String.IsNullOrEmpty(row["isSum"] + ""))
|
|
{
|
|
int isSum = Convert.ToInt32(row["isSum"]);
|
|
//处理统计
|
|
if (isSum == 1)
|
|
{
|
|
treeList.OptionsView.ShowSummaryFooter = true;
|
|
gridColumn.RowFooterSummary = DevExpress.XtraTreeList.SummaryItemType.Sum;
|
|
gridColumn.AllNodesSummary = true;
|
|
gridColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
|
|
gridColumn.RowFooterSummaryStrFormat = "{0:" + dataFormat + "}";
|
|
}
|
|
}
|
|
}
|
|
treeList.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { gridColumn });
|
|
if (treeList.Columns.Count > 0)
|
|
{
|
|
DevExpress.XtraTreeList.Columns.TreeListColumn firstColumn = treeList.Columns[0];
|
|
if (firstColumn != null)
|
|
{
|
|
treeList.OptionsView.ShowSummaryFooter = true;
|
|
firstColumn.AllNodesSummary = true;
|
|
firstColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Count;
|
|
firstColumn.RowFooterSummaryStrFormat = "合计:{0:#,###}行";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 执行右键菜单后刷新表格数据
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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<string> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 找到所有树节点
|
|
/// </summary>
|
|
/// <param name="parentNode"></param>
|
|
/// <param name="list"></param>
|
|
/// <returns></returns>
|
|
private void GetChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode parentNode, List<DevExpress.XtraTreeList.Nodes.TreeListNode> list)
|
|
{
|
|
if (parentNode.Nodes.Count > 0)
|
|
{
|
|
foreach (DevExpress.XtraTreeList.Nodes.TreeListNode node in parentNode.Nodes)
|
|
{
|
|
list.Add(node);
|
|
if (node.Nodes.Count > 0)
|
|
{
|
|
GetChildNodes(node, list);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取选中行数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private DataRow getSelectNodeRow(DevExpress.XtraTreeList.Nodes.TreeListNode node)
|
|
{
|
|
DataRowView dataRowView = treeList.GetDataRecordByNode(node) as DataRowView;
|
|
return dataRowView != null ? dataRowView.Row : null;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
//if (TreeGridState)
|
|
//{
|
|
// selectNode = treeList.FocusedNode;
|
|
// if (selectNode == null) MessageBox.Show("没有符合删除条件的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
// if (MessageBox.Show("您确定要删除选中记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
// {
|
|
// List<DevExpress.XtraTreeList.Nodes.TreeListNode> list = new List<DevExpress.XtraTreeList.Nodes.TreeListNode>();
|
|
// GetChildNodes(selectNode, list);
|
|
// this.treeList.DeleteNode(selectNode);
|
|
// string ids = string.Empty;
|
|
// foreach (DevExpress.XtraTreeList.Nodes.TreeListNode rid in list)
|
|
// {
|
|
// DataRow item = getSelectNodeRow(rid);
|
|
// if (string.IsNullOrEmpty(item["tree_id"] + "")) continue;
|
|
// ids += "'" + item["tree_id"] + "',";
|
|
// }
|
|
// if (ids != string.Empty)
|
|
// {
|
|
// string sql = "delete from " + dtSystemDlltab.Rows[0]["SQLDT1"] + " where tree_id in(" + ids.Trim(',') + ")";
|
|
// SqlHelper.ExecuteNonQuery(sql);
|
|
// InitData(gridList.Sql);
|
|
// MessageBox.Show("记录删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
// }
|
|
// else
|
|
// {
|
|
// MessageBox.Show("没有符合删除条件的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
// }
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
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
|
|
{
|
|
//bool state = false;
|
|
//if (TreeGridState)
|
|
//{
|
|
// AddTreeNodeForm AddNodeform = new AddTreeNodeForm();
|
|
// DialogResult res = AddNodeform.ShowDialog();
|
|
// state = AddNodeform.TreeNodeflag == 0;
|
|
//}
|
|
if (!string.IsNullOrEmpty(dtSystemDlltab.Rows[0]["AddDllName"] + ""))
|
|
{
|
|
string[] args = {
|
|
FormText,
|
|
OperatorId,
|
|
OperatorName,
|
|
Privilege,
|
|
DLLCoid,
|
|
"",
|
|
"",
|
|
"",
|
|
objectId,
|
|
objectValue,
|
|
dllSql,
|
|
// state?getSelectNodeRow(treeList.FocusedNode)["tree_pid"]+"":getSelectNodeRow(treeList.FocusedNode)["tree_id"]+""
|
|
};
|
|
IForm form = PubUtil.LoadDllForm(dtSystemDlltab.Rows[0]["AddDllName"] + "", args);
|
|
DialogResult result = form.SubForm.ShowDialog();
|
|
InitData(gridList.Sql);
|
|
RefreshTabPageTitle();
|
|
}
|
|
else
|
|
{
|
|
AddRow(gridList.gridView);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加行
|
|
/// </summary>
|
|
/// <param name="view"></param>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出Excel
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnExport_Click(object sender, EventArgs e)
|
|
{
|
|
PubClass.SaveXls(gridList.gridControl);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入Excel
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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;
|
|
}
|
|
//if (TreeGridState)
|
|
//{
|
|
// DataRow row= getSelectNodeRow(treeList.FocusedNode);
|
|
// if(row==null)MessageBox.Show("请选中一行");
|
|
// string productId1 = row[idFiledKey.Rows[0]["fieldname"] + ""].ToString();
|
|
|
|
// if (!string.IsNullOrEmpty(dtSystemDlltab.Rows[0]["AddDllName"] + ""))
|
|
// {
|
|
// string[] args = {
|
|
// FormText,
|
|
// OperatorId,
|
|
// OperatorName,
|
|
// Privilege,
|
|
// DLLCoid,
|
|
// "",
|
|
// "",
|
|
// "",
|
|
// productId1,
|
|
// "",
|
|
// "",
|
|
// row["tree_id"]+"",
|
|
// dllSql
|
|
// };
|
|
// IForm form = PubUtil.LoadDllForm(dtSystemDlltab.Rows[0]["AddDllName"] + "", args);
|
|
// DialogResult result = form.SubForm.ShowDialog();
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
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
|
|
{
|
|
//gridSave();
|
|
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("修改成功");
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 表格必须录入验证
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// 多表表格修改
|
|
/// </summary>
|
|
private void gridSave()
|
|
{
|
|
try
|
|
{
|
|
Dictionary<string, string> dics = new Dictionary<string, string>();
|
|
|
|
if (dtSystemDlltab == null || dtSystemDlltab.Rows.Count == 0) return;
|
|
|
|
string tabName = dtSystemDlltab.Rows[0]["SQLDT1"] + "";
|
|
if (string.IsNullOrEmpty(tabName))
|
|
{
|
|
XtraMessageBox.Show("检测到未设置表名");
|
|
return;
|
|
}
|
|
|
|
List<string> mList = new List<string>();
|
|
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<DataRow> modifiedRows = dtTable.Rows.Cast<DataRow>().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<DataRow>().FirstOrDefault(x => col.ColumnName.Equals(x["fieldname"] + "", StringComparison.OrdinalIgnoreCase));
|
|
if (hasContainRow != null && col.ColumnName != mParmaryKey && col.ColumnName != "id")
|
|
{
|
|
if (row.RowState == DataRowState.Modified)
|
|
{
|
|
// 禁编列不更新,20180411取消,由于禁编列可能存在计算,导致计算后无法保存.
|
|
//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]);
|
|
dics.Add(updateSql, 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 % 5 == 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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化数据
|
|
/// </summary>
|
|
/// <param name="sql"></param>
|
|
public void InitData(string sql)
|
|
{
|
|
this.oldSql = sql;
|
|
da = SqlHelper.ExecuteAdapter(CommandType.Text, sql);
|
|
if (ds != null && ds.Tables.Count > 0)
|
|
ds.Clear();
|
|
da.Fill(ds);
|
|
SqlCommandBuilder cb = new SqlCommandBuilder(da);
|
|
//if (TreeGridState)
|
|
//{
|
|
// this.treeList.DataSource = ds.Tables[0];
|
|
//}
|
|
//else
|
|
//{
|
|
int oldRowHandle = (gridList.gridView).FocusedRowHandle;
|
|
gridList.gridControl.DataSource = ds.Tables[0];
|
|
(gridList.gridView).ClearSelection();
|
|
(gridList.gridView).FocusedRowHandle = oldRowHandle;
|
|
(gridList.gridView).SelectRow(oldRowHandle);
|
|
// }
|
|
setButtonStatus();
|
|
}
|
|
/// <summary>
|
|
/// 刷新标题
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
}
|