1919 lines
82 KiB
C#
1919 lines
82 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 DevExpress.XtraTab;
|
||
using DevExpress.XtraEditors;
|
||
using DevExpress.XtraGrid.Columns;
|
||
using Lskj.MyControl;
|
||
using System.Data.SqlClient;
|
||
using DevExpress.XtraGrid.Views.Grid;
|
||
using DevExpress.Utils;
|
||
using DevExpress.Data;
|
||
using DevExpress.XtraGrid;
|
||
using CommonLib.utils;
|
||
using ExcelPlus;
|
||
|
||
namespace Lskj.PubPageModuleDetail
|
||
{
|
||
public partial class TabPageContainer : UserControl
|
||
{
|
||
#region 需要传入的参数
|
||
public string OperatorId, OperatorName, DLLCoid, FormText, Privilege;
|
||
public Form baseForm;
|
||
#endregion
|
||
|
||
#region 私有属性
|
||
/// <summary>
|
||
/// 左边显示类型
|
||
/// </summary>
|
||
private int LeftType;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
private List<ToolStripMenuItem> tsmMenuList = new List<ToolStripMenuItem>();
|
||
private DataTable dtColumns;
|
||
private string mPrimaryKey; // 主界面主键
|
||
private int leftWidth; //宽度
|
||
private int mRightGridMode; // 右边参数模式,1.面板模式,2.标签模式
|
||
private int mRightGridDataMode; // 右边表格模式,1.明细列表数据,2.报表明细模式
|
||
/// <summary>
|
||
/// 表格颜色
|
||
/// </summary>
|
||
private DataTable mGridColorList;
|
||
private DataTable mGridSum;
|
||
private DataRow mSystemRow;
|
||
private DataRow[] mNullableFields;
|
||
private string mAddCond, mModifyCond, mDeleteCond, mDragCond, mTableName;
|
||
private string mTreeTags; // 选中的数节点数据
|
||
private int mSearchHide;
|
||
private int mSeearchMode; // 查询模式,1.查询条件,2.下拉列表查询
|
||
private int mLeftType;
|
||
/// <summary>
|
||
/// 表格是否可以编辑
|
||
/// </summary>
|
||
private bool mGridEdited;
|
||
private bool mNeedModify;
|
||
/// <summary>
|
||
/// 是否为点击查询按钮获取数据
|
||
/// </summary>
|
||
public bool mIsSearch = true;
|
||
private bool inSummary = false;
|
||
|
||
public DataRow drLeft;
|
||
public MySearchCreateControl mcc = new MySearchCreateControl();
|
||
public MySearchCreateControl mccTop = new MySearchCreateControl();
|
||
public string BeforeSearchSQL;
|
||
|
||
/// <summary>
|
||
/// DbDataAdapter
|
||
/// </summary>
|
||
private SqlDataAdapter GridAdapter { get; set; }
|
||
/// <summary>
|
||
/// 操作Dataset
|
||
/// </summary>
|
||
private DataSet GridDataSet = new DataSet();
|
||
public GridControlEx GetGridControl;
|
||
public GridControl GridLeftEx;
|
||
#endregion
|
||
|
||
#region 缓存数据
|
||
/// <summary>
|
||
/// 基础档案、报表明细列表数据
|
||
/// </summary>
|
||
private DataTable moduleDetailTable = new DataTable();
|
||
private DataTable moduleDetailBottomTable = new DataTable();
|
||
/// <summary>
|
||
/// 缓存底部多标签
|
||
/// </summary>
|
||
private Dictionary<string, XtraTabControl> mButtomTabPages = new Dictionary<string, XtraTabControl>();
|
||
#endregion
|
||
|
||
#region 构造函数
|
||
public TabPageContainer(string OperatorId, string OperatorName, string DLLCoid, string FormText, string Privilege)
|
||
{
|
||
this.OperatorId = OperatorId;
|
||
this.OperatorName = OperatorName;
|
||
this.DLLCoid = DLLCoid;
|
||
this.FormText = FormText;
|
||
this.Privilege = Privilege;
|
||
|
||
//DevExpress.XtraGrid.Localization.GridResLocalizer.Active = new Dxper.LocalizationCHS.Win.XtraGridCHS();
|
||
//DevExpress.XtraEditors.Controls.Localizer.Active = new Dxper.LocalizationCHS.Win.XtraEditorsCHS();
|
||
//DevExpress.XtraLayout.Localization.LayoutLocalizer.Active = new Dxper.LocalizationCHS.Win.XtraLayoutCHS();
|
||
//DevExpress.XtraPrinting.Localization.PreviewLocalizer.Active = new Dxper.LocalizationCHS.Win.XtraPrintingCHS();
|
||
InitializeComponent();
|
||
tvLeft.GetTreeView.AfterCheck += new TreeViewEventHandler(tvLeft_AfterCheck);
|
||
tvLeft.GetTreeView.AfterSelect += new TreeViewEventHandler(tvLeft_AfterSelect);
|
||
|
||
gcMain.gridView.IndicatorWidth = 40;
|
||
gcMain.gridView.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
|
||
gcMain.gridView.RowStyle += new RowStyleEventHandler(gridView_RowStyle);
|
||
gcMain.gridView.ShowingEditor += new CancelEventHandler(gridView_ShowingEditor);
|
||
gcMain.gridView.DoubleClick += new EventHandler(gridView_DoubleClick);
|
||
gcMain.gridView.SelectionChanged +=new SelectionChangedEventHandler(gridView_SelectionChanged);
|
||
gcMain.gridView.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridView_CellValueChanged);
|
||
}
|
||
#endregion
|
||
|
||
#region 初始化
|
||
protected override void OnLoad(EventArgs e)
|
||
{
|
||
DataTable dtTag3 = SqlHelper.ExecuteDataSet("select * from P_systemwordbooktab where tab='" + DLLCoid + "' and fieldsqlTag=3").Tables[0];
|
||
if (dtTag3 != null && dtTag3.Rows.Count > 0)
|
||
drLeft = dtTag3.Rows[0];
|
||
|
||
mSystemRow = SqlHelper.ExecuteDataSet(string.Format("select * from P_systemDlltab where DLLCoid='{0}'", DLLCoid)).Tables[0].Rows[0];
|
||
mGridColorList = SqlHelper.ExecuteDataSet(string.Format("select * from P_systemwordbookcolor where tab='{0}' and useflag=0 order by orderid", DLLCoid)).Tables[0];
|
||
|
||
mSystemRow["SQL"] = PubClass.ReqSqlParam(mSystemRow["SQL"] + "", OperatorId, OperatorName);
|
||
|
||
this.LeftType = Convert.ToInt32(mSystemRow["dllType"]);
|
||
this.leftWidth = Convert.ToInt32(mSystemRow["leftWidth"] + "");
|
||
this.mPrimaryKey = getParimaryKey(DLLCoid);
|
||
this.plLeft.Width = leftWidth > 0 ? leftWidth : plLeft.Width;
|
||
|
||
// 处理表格是否可以编辑
|
||
mNeedModify = mSystemRow["modifyEnable"] + "" == "1";
|
||
mGridEdited = (string.IsNullOrEmpty(mSystemRow["selfEdit"] + "") || mSystemRow["selfEdit"] + "" == "0" || mSystemRow["selfEdit"] + "" == "False") ? false : true;
|
||
gcMain.gridView.OptionsBehavior.Editable = mGridEdited;
|
||
btnSave.Enabled = mGridEdited;
|
||
|
||
mAddCond = mSystemRow["addCond"] + "";
|
||
mModifyCond = mSystemRow["modifyCond"] + "";
|
||
mDeleteCond = mSystemRow["deleteCond"] + "";
|
||
mDragCond = mSystemRow["dragCond"] + "";
|
||
mTableName = mSystemRow["SQLDT1"] + "";
|
||
mSearchHide = Convert.ToInt32(mSystemRow["searchHide"] + "");
|
||
mLeftType = Convert.ToInt32(mSystemRow["dllType"]);
|
||
pl_search.Visible = mSearchHide != 1;
|
||
|
||
//模板添加删除修改导入导出
|
||
btnAdd.Enabled = mSystemRow["addEnable"] + "" == "1";
|
||
btnDelete.Enabled = mSystemRow["deleteEnable"] + "" == "1";
|
||
btnSave.Enabled = mSystemRow["modifyEnable"] + "" == "1" && mGridEdited;
|
||
gcMain.gridView.OptionsBehavior.Editable = mSystemRow["modifyEnable"] + "" == "1" && mGridEdited;
|
||
btnImprt.Enabled = mSystemRow["importEnable"] + "" == "1";
|
||
btnExport.Enabled = mSystemRow["exportEnable"] + "" == "1";
|
||
|
||
btnCondSearch.Enabled = mSystemRow["searchEnable"] + "" == "1";
|
||
cbField.Enabled = mSystemRow["searchEnable"] + "" == "1";
|
||
txtKey.Enabled = mSystemRow["searchEnable"] + "" == "1";
|
||
|
||
// 加载默认右侧多标签,默认加载为上下结构的表格
|
||
this.LoadDllDetailWithPanelPage(DLLCoid);
|
||
// 加载默认底部多标签
|
||
this.LoadDllDeatilWithBottomTabPage(DLLCoid);
|
||
|
||
if (btnAdd.Enabled && !btnDelete.Enabled && !btnSave.Enabled)
|
||
{
|
||
pl_down.Visible = false;
|
||
}
|
||
|
||
// 加载筛选框
|
||
DataTable cbSearchFiled = SqlHelper.ExecuteDataSet("select username1,fieldname from P_systemwordbooktab where tab='" + DLLCoid + "' and ifSearch =0 and isnull(username1,'')<>''").Tables[0];
|
||
cbField.DataSource = cbSearchFiled;
|
||
cbField.DisplayMember = "username1";
|
||
cbField.ValueMember = "fieldname";
|
||
|
||
// 查询统计列
|
||
string isSumSql = "select * from p_systemwordbooktab where tab='" + DLLCoid + "' and isnull(vislble,0)=0 and isnull(calcExpr,'')<>''order by calcOrder asc";
|
||
mGridSum = SqlHelper.ExecuteDataSet(isSumSql).Tables[0];
|
||
|
||
//左边树结构
|
||
if (LeftType == 1)
|
||
{
|
||
tvLeft.Visible = true;
|
||
gridLeft.Visible = plContainer.Visible = pl_right_where.Visible = false;
|
||
|
||
PubClass.BindTree(drLeft["fieldsql"] + "", tvLeft.GetTreeView);
|
||
gcMain.gridView.OptionsSelection.MultiSelect = true;
|
||
GridDragTree gridDragTree = new GridDragTree(baseForm, gcMain.gridControl, tvLeft.GetTreeView, Drag_EventHandler, drLeft, mSystemRow["SQLDT1"] + "", mPrimaryKey);
|
||
}
|
||
else if (LeftType == 2)
|
||
{
|
||
tvLeft.Visible = false;
|
||
gridLeft.Visible = true;
|
||
|
||
string sql = "select * from p_systemwordbookgrid where fieldid=" + drLeft["id"] + " order by orderid";
|
||
DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
|
||
for (int i = 0; i < dt.Rows.Count; i++)
|
||
{
|
||
DataRow row = dt.Rows[i];
|
||
GridColumn gridColumn = new GridColumn();
|
||
gridColumn.FieldName = row["fieldname"] + "";
|
||
gridColumn.Name = row["fieldname"] + "";
|
||
gridColumn.VisibleIndex = i;
|
||
gridColumn.Caption = row["username"] + "";
|
||
gridColumn.Width = Convert.ToInt32(row["width"]);
|
||
gridColumn.Visible = Convert.ToInt32(row["visible"]) == 0;
|
||
GridViewLeft.Columns.Add(gridColumn);
|
||
}
|
||
SearchCraeteControl();
|
||
gcMain.gridView.OptionsSelection.MultiSelect = true;
|
||
GridDrag2GridUpdate g2g = new GridDrag2GridUpdate(gcMain.gridControl, gridLeft, DragGridCallBack);
|
||
}
|
||
else
|
||
{
|
||
plLeft.Visible = false;
|
||
splitterControl1.Visible = false;
|
||
}
|
||
|
||
this.SearchCreateTopControl();
|
||
this.InitColumns();
|
||
this.InitMenu();
|
||
this.SearchData();
|
||
|
||
// 这个位置怪的很,居然不计算
|
||
int x_width = this.pl_down.Location.X + this.pl_down.Width;
|
||
|
||
btnPrint.Location = new Point(x_width - btnPrint.Width - 5, btnPrint.Location.Y);
|
||
btnSave.Location = new Point(btnPrint.Location.X - btnSave.Width - 5, btnSave.Location.Y);
|
||
btnDelete.Location = new Point(btnSave.Location.X - btnDelete.Width - 5, btnDelete.Location.Y);
|
||
btnAdd.Location = new Point(btnDelete.Location.X - btnAdd.Width - 5, btnAdd.Location.Y);
|
||
}
|
||
#endregion
|
||
|
||
#region 表格拖动
|
||
/// <summary>
|
||
/// 拖动权限
|
||
/// </summary>
|
||
/// <param name="dr"></param>
|
||
/// <returns></returns>
|
||
private bool CanDragRowState(DataRow dr)
|
||
{
|
||
try
|
||
{
|
||
string tempCond = mDragCond;
|
||
bool canDrag = string.IsNullOrEmpty(mDragCond);
|
||
if (!string.IsNullOrEmpty(tempCond))
|
||
{
|
||
tempCond = PubClass.ReqSqlWhere(dr, PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
|
||
canDrag = Convert.ToBoolean(Evaluator.Eval(tempCond));
|
||
}
|
||
return canDrag;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public void DragGridCallBack(object sender)
|
||
{
|
||
if (XtraMessageBox.Show("您确定要拖动选中记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
GridView targetGridView = (sender as GridControl).FocusedView as GridView;
|
||
string tableName = mSystemRow["SQLDT1"] + "";
|
||
string unionField = drLeft["fieldsqlid"] + "";
|
||
string parmaryKey = mPrimaryKey;
|
||
int[] sourceSelectRows = gcMain.gridView.GetSelectedRows();
|
||
int[] targetSelectRows = targetGridView.GetSelectedRows();
|
||
try
|
||
{
|
||
// 拖动结果
|
||
int dragSuccess = 0, dragError = 0, result = 0;
|
||
string ids = string.Empty;
|
||
foreach (int item in sourceSelectRows)
|
||
{
|
||
DataRow dr = gcMain.gridView.GetDataRow(item);
|
||
if (CanDragRowState(dr))
|
||
{
|
||
ids += "'" + dr[parmaryKey] + "',";
|
||
dragSuccess++;
|
||
}
|
||
else
|
||
{
|
||
dragError++;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(ids) && targetSelectRows.Count() > 0)
|
||
{
|
||
DataRow drTarget = targetGridView.GetDataRow(targetSelectRows[0]);
|
||
string sqlValue = string.Format("UPDATE {0} SET {1}='{2}' WHERE {3} IN ({4})",
|
||
tableName, unionField, drTarget[unionField], parmaryKey, ids.Trim(','));
|
||
result = SqlHelper.ExecuteNonQuery(sqlValue);
|
||
// 刷新左侧表格数据
|
||
mcc.runQuery();
|
||
// 刷新主表格数据
|
||
if (mSystemRow["searchEnable"] + "" == "1")
|
||
{
|
||
if (mSeearchMode == 1)
|
||
{
|
||
sqlValue = mccTop.SetSearchSqlValue();
|
||
if (!string.IsNullOrEmpty(sqlValue))
|
||
{
|
||
InitData(sqlValue);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
btnCondSearch_Click(null, null);
|
||
}
|
||
}
|
||
}
|
||
XtraMessageBox.Show("拖动成功 " + dragSuccess + " 条," + "失败 " + dragError + " 条", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 搜索条件
|
||
/// <summary>
|
||
/// 创建左侧查询条件
|
||
/// </summary>
|
||
public void SearchCraeteControl()
|
||
{
|
||
string sql = string.Format("exec p_getControlLocation '{0}','{1}','{2}'", drLeft["fieldKey"], DLLCoid, OperatorName);
|
||
DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
string condSql = string.Format("select * from p_systembillsourcecond where formKey='{0}'", drLeft["fieldKey"]);
|
||
mcc.LoginId = OperatorId;
|
||
mcc.LoginName = OperatorName;
|
||
mcc.SearchSql = PubClass.ReplaceWhereCond(drLeft["fieldsql"] + "");
|
||
mcc.ctr = pl_right_where;
|
||
mcc.gce = gridLeft;
|
||
mcc.dllType = LeftType;
|
||
mcc.condDt = SqlHelper.ExecuteDataSet(condSql).Tables[0];
|
||
CreateControlModel cm = new CreateControlModel();
|
||
cm.dt = dt;
|
||
cm.ctr = pl_right_where;
|
||
cm.loginid = OperatorId;
|
||
cm.loginname = OperatorName;
|
||
int height = mcc.CreateControlByModel(cm);
|
||
pl_right_where.Height = height;
|
||
Control[] ctl = pl_right_where.Controls.Find("btnCondSearch", true);
|
||
if ((ctl != null) && (ctl.Length > 0))
|
||
{
|
||
(ctl[0] as SimpleButton).Width = 72;
|
||
}
|
||
mcc.runQuery();
|
||
}
|
||
else
|
||
{
|
||
gridLeft.DataSource = SqlHelper.ExecuteDataSet(drLeft["fieldsql"] + "").Tables[0];
|
||
pl_right_where.Visible = false;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 中间表格行点击操作
|
||
/// <summary>
|
||
/// 表格点击
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public void gridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
{
|
||
string primaryKey = getParimaryKey(DLLCoid);
|
||
SetDetailData(DLLCoid, primaryKey);
|
||
}
|
||
#endregion
|
||
|
||
#region 选择树
|
||
protected void tvLeft_AfterSelect(object sender, TreeViewEventArgs e)
|
||
{
|
||
LeftTreeAfterSelect(sender, e);
|
||
}
|
||
#endregion
|
||
|
||
#region 绑定树
|
||
protected void tvLeft_AfterCheck(object sender, TreeViewEventArgs e)
|
||
{
|
||
if (e.Action == TreeViewAction.ByMouse)
|
||
{
|
||
//取消节点选中状态之后,取消所有父节点的选中状态
|
||
if (e.Node.Checked)
|
||
{
|
||
setChildNodeCheckedState(e.Node, true);
|
||
}
|
||
else
|
||
{
|
||
//取消节点选中状态之后,取消所有父节点的选中状态
|
||
setChildNodeCheckedState(e.Node, false);
|
||
//如果节点存在父节点,取消父节点的选中状态
|
||
if (e.Node.Parent != null)
|
||
{
|
||
setParentNodeCheckedState(e.Node, false);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取消节点选中状态之后,取消所有父节点的选中状态
|
||
/// </summary>
|
||
/// <param name="currNode"></param>
|
||
/// <param name="state"></param>
|
||
private void setParentNodeCheckedState(TreeNode currNode, bool state)
|
||
{
|
||
TreeNode parentNode = currNode.Parent;
|
||
parentNode.Checked = state;
|
||
if (currNode.Parent.Parent != null)
|
||
{
|
||
setParentNodeCheckedState(currNode.Parent, state);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选中节点之后,选中节点的所有子节点
|
||
/// </summary>
|
||
/// <param name="currNode"></param>
|
||
/// <param name="state"></param>
|
||
private void setChildNodeCheckedState(TreeNode currNode, bool state)
|
||
{
|
||
TreeNodeCollection nodes = currNode.Nodes;
|
||
if (nodes.Count > 0)
|
||
foreach (TreeNode tn in nodes)
|
||
{
|
||
tn.Checked = state;
|
||
setChildNodeCheckedState(tn, state);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 左边树点击事件
|
||
private void gridViewLeft_RowCellClick(object sender, RowCellClickEventArgs e)
|
||
{
|
||
LeftGridCellClick(sender, e);
|
||
}
|
||
#endregion
|
||
|
||
#region 基础档案、报表右侧明细表格
|
||
/// <summary>
|
||
/// 加载右侧多标签,添加在一个面板上,显示为上下结构的表格,只加载报表表格
|
||
/// </summary>
|
||
public void LoadDllDetailWithPanelPage(string menuId)
|
||
{
|
||
tabMain.Visible = false;
|
||
mRightGridMode = 1;
|
||
mRightGridDataMode = 1;
|
||
// 获取配置明细列表
|
||
moduleDetailTable = SqlHelper.ExecuteDataSet("select a.*,b.SQL from p_systemDlltabDetail a inner join p_systemdlltab b on a.UnionModule = b.DllCoid where a.tab='" + menuId + "' and a.isVisible=0 and a.rightVisible=1 order by a.orderid").Tables[0];
|
||
// 明细列表没有数据,则获取报表明细配置,兼容旧版本
|
||
if (moduleDetailTable == null || moduleDetailTable.Rows.Count == 0)
|
||
{
|
||
moduleDetailTable = SqlHelper.ExecuteDataSet("select * from p_systemDlltabDetail where tab='" + menuId + "' and isVisible=0 and rightVisible=1 order by orderid").Tables[0];
|
||
mRightGridDataMode = 2;
|
||
}
|
||
int count = moduleDetailTable.Rows.Count;
|
||
int currentHeight = 2;
|
||
foreach (DataRow row in moduleDetailTable.Rows)
|
||
{
|
||
Panel panel = new Panel();
|
||
GroupBox gb = new GroupBox();
|
||
gb.Text = row["detailName"] + "";
|
||
gb.Dock = DockStyle.Fill;
|
||
GridControlEx dgv = CreateDetailDgvWithTabPage(row);
|
||
GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", dgv.gridControl);
|
||
gm.BindGridMenu(row["formKey"] + "");
|
||
dgv.Name = "grid";
|
||
dgv.Dock = DockStyle.Fill;
|
||
dgv.gridView.OptionsView.ShowFooter = true;
|
||
dgv.gridView.Tag = moduleDetailTable.Columns.Contains("SQL") ? row["SQL"] : row["detailSql"];
|
||
gb.Controls.Add(dgv);
|
||
panel.Controls.Add(gb);
|
||
panel.Tag = row;
|
||
panel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
||
panel.Top = currentHeight;
|
||
panel.Width = plRightGrid.Width;
|
||
currentHeight += panel.Height = plRightGrid.Height / count;
|
||
plRightGrid.Controls.Add(panel);
|
||
}
|
||
if (moduleDetailTable.Rows.Count == 0)
|
||
{
|
||
tabMain.Visible = plRightGrid.Visible = splitterControl2.Visible = false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 加载右侧多标签,添加在多标签上,只加载报表表格
|
||
/// </summary>
|
||
public void LoadDllDeatilWithTabPage(string menuId)
|
||
{
|
||
mRightGridMode = 2;
|
||
mRightGridDataMode = 1;
|
||
tabMain.TabPages.Clear();
|
||
// 获取配置明细列表
|
||
moduleDetailTable = SqlHelper.ExecuteDataSet("select a.*,b.SQL from p_systemDlltabDetail a inner join p_systemdlltab b on a.UnionModule = b.DllCoid where a.tab='" + menuId + "' and a.isVisible=0 and a.rightVisible=1 order by a.orderid").Tables[0];
|
||
// 明细列表没有数据,则获取报表明细配置,兼容旧版本
|
||
if (moduleDetailTable == null || moduleDetailTable.Rows.Count == 0)
|
||
{
|
||
moduleDetailTable = SqlHelper.ExecuteDataSet("select * from p_systemDlltabDetail where tab='" + menuId + "' and isVisible=0 and rightVisible=1 order by orderid").Tables[0];
|
||
mRightGridDataMode = 2;
|
||
}
|
||
foreach (DataRow row in moduleDetailTable.Rows)
|
||
{
|
||
XtraTabPage tabPage = new XtraTabPage();
|
||
tabPage.Text = row["detailName"] + "";
|
||
GridControlEx dgv = CreateDetailDgvWithTabPage(row);
|
||
dgv.Name = "grid" + row["id"];
|
||
///
|
||
dgv.ModuleType = 2;
|
||
dgv.ModuleKey = row["formKey"].ToString();
|
||
////
|
||
dgv.Tag = row;
|
||
GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", dgv.gridControl);
|
||
gm.BindGridMenu(row["formKey"].ToString());
|
||
tabPage.Controls.Add(dgv);
|
||
dgv.gridView.Tag = moduleDetailTable.Columns.Contains("SQL") ? row["SQL"] : row["detailSql"];
|
||
dgv.gridView.OptionsView.ShowFooter = true;
|
||
dgv.Dock = DockStyle.Fill;
|
||
|
||
tabPage.Tag = dgv;
|
||
tabMain.TabPages.Add(tabPage);
|
||
}
|
||
if (moduleDetailTable.Rows.Count == 0)
|
||
{
|
||
tabMain.Visible = plRightGrid.Visible = splitterControl2.Visible = false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 创建表格,为了兼容之前版本先取报表配置列,未配置则取报表明细列
|
||
/// </summary>
|
||
/// <param name="row"></param>
|
||
/// <returns></returns>
|
||
public GridControlEx CreateDetailDgvWithTabPage(DataRow row)
|
||
{
|
||
var detailId = Convert.ToInt32(row["Id"]);
|
||
var detailSql = Convert.ToString(row["detailSql"]);
|
||
var unionModule = row["UnionModule"] + "";
|
||
|
||
GridControlEx gcEx = new GridControlEx();
|
||
// 取报表配置列
|
||
SqlParameter[] p =
|
||
{
|
||
new SqlParameter("@modid",SqlDbType.VarChar,20),
|
||
new SqlParameter("@operatorname",SqlDbType.VarChar,20)
|
||
};
|
||
p[0].Value = row["UnionModule"];
|
||
p[1].Value = OperatorName;
|
||
DataTable dtFileds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "[p_getBaseModuleField]", "temp", p).Tables[0];
|
||
|
||
if (dtFileds != null && dtFileds.Rows.Count == 0)
|
||
{
|
||
// 取报表明细列
|
||
SqlParameter[] p1 =
|
||
{
|
||
new SqlParameter("@modid",SqlDbType.VarChar,50),
|
||
new SqlParameter("@detailid",SqlDbType.Int,4),
|
||
new SqlParameter("@operatorname",SqlDbType.VarChar,50)
|
||
};
|
||
p1[0].Value = unionModule;
|
||
p1[1].Value = detailId;
|
||
p1[2].Value = OperatorName;
|
||
dtFileds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_getBaseModuleDetailField", "temp", p1).Tables[0];
|
||
gcEx.SetColumns(dtFileds);
|
||
gcEx.gridView.RowCellStyle += new RowCellStyleEventHandler(gridView_RowCellStyle);
|
||
}
|
||
else
|
||
{
|
||
gcEx.SetColumns2(dtFileds);
|
||
}
|
||
detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName);
|
||
gcEx.gridView.Tag = detailSql;
|
||
gcEx.RowColorCondtion = SqlHelper.ExecuteDataSet(string.Format("select * from p_systemwordbookcolor where isnull(useflag,0)=0 and tab ='{0}' order by orderid", row["formkey"])).Tables[0];
|
||
return gcEx;
|
||
}
|
||
/// <summary>
|
||
/// 设置右侧表格数据
|
||
/// </summary>
|
||
private void SetRightGridData(string primaryKey, DataRow drRow)
|
||
{
|
||
switch (mRightGridMode)
|
||
{
|
||
case 1: // 面板模式
|
||
SetRightPanelGridData(primaryKey, drRow);
|
||
break;
|
||
case 2:// 标签模式
|
||
SetRightTabGridData(primaryKey, drRow);
|
||
break;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 设置右侧面板表格数据
|
||
/// </summary>
|
||
private void SetRightPanelGridData(string primaryKey, DataRow row)
|
||
{
|
||
foreach (Control item in plRightGrid.Controls)
|
||
{
|
||
if (item.Controls.Count > 0 && item.Controls[0].Controls.Count > 0)
|
||
{
|
||
GridControlEx gc = item.Controls[0].Controls[0] as GridControlEx;
|
||
gc.gridView.OptionsBehavior.Editable = false;
|
||
DataRow drRight = item.Tag as DataRow;
|
||
string sql = gc.gridView.Tag + "";
|
||
string fieldName = primaryKey;
|
||
string fieldValue = row[fieldName] + "";
|
||
string detailSql = PubClass.ReplaceWhereCond(PubClass.ReqSql(row, sql));
|
||
string unionValue = (drRight["unionValue"] + "").Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "");
|
||
if (!string.IsNullOrEmpty(detailSql))
|
||
{
|
||
detailSql += " and " + unionValue + " = '" + fieldValue + "'";
|
||
}
|
||
|
||
// 列表模式
|
||
if (mRightGridDataMode == 1)
|
||
{
|
||
detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName);
|
||
}
|
||
else
|
||
{ // 报表明细模式
|
||
detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName);
|
||
List<string> paramList = PubClass.GetParamValue(detailSql);
|
||
foreach (string param in paramList)
|
||
{
|
||
string fileName = param.Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "");
|
||
if (dtColumns.Columns.Contains(fieldName))
|
||
{
|
||
detailSql = detailSql.Replace(param, row[fileName] + "");
|
||
}
|
||
}
|
||
}
|
||
gc.SetDataSource(detailSql);
|
||
gc.gridView.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 设置右侧多标签数据
|
||
/// </summary>
|
||
/// <param name="row"></param>
|
||
private void SetRightTabGridData(string primaryKey, DataRow row)
|
||
{
|
||
foreach (XtraTabPage tab in tabMain.TabPages)
|
||
{
|
||
GridControlEx gc = tab.Tag as GridControlEx;
|
||
DataRow drRight = gc.Tag as DataRow;
|
||
string sql = gc.gridView.Tag + "";
|
||
string fieldName = primaryKey;
|
||
string fieldValue = row[fieldName] + "";
|
||
string detailSql = PubClass.ReplaceWhereCond(PubClass.ReqSql(row, sql));
|
||
string unionValue = (drRight["unionValue"] + "").Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "");
|
||
if (!string.IsNullOrEmpty(detailSql))
|
||
{
|
||
detailSql += " and " + unionValue + " = '" + fieldValue + "'";
|
||
}
|
||
// 列表模式
|
||
if (mRightGridDataMode == 1)
|
||
{
|
||
detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName);
|
||
}
|
||
else
|
||
{ // 报表明细模式
|
||
detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName);
|
||
List<string> paramList = PubClass.GetParamValue(detailSql);
|
||
foreach (string param in paramList)
|
||
{
|
||
string fileName = param.Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "");
|
||
if (dtColumns.Columns.Contains(fieldName))
|
||
{
|
||
detailSql = detailSql.Replace(param, row[fileName] + "");
|
||
}
|
||
}
|
||
}
|
||
gc.SetDataSource(detailSql + " and " + unionValue + " = '" + fieldValue + "'");
|
||
gc.gridView.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 设置行颜色
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void gridView_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
|
||
{
|
||
if (e.RowHandle >= 0)
|
||
{
|
||
XtraTabPage tagpage = tabMain.SelectedTabPage;
|
||
GridControlEx gce = tagpage.Tag 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<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
|
||
|
||
#region 加载底部多标签
|
||
/// <summary>
|
||
/// 加载底部标签(可支持基础档案和报表)
|
||
/// </summary>
|
||
private void LoadDllDeatilWithBottomTabPage(string menuId)
|
||
{
|
||
// 获取配置明细列表
|
||
moduleDetailBottomTable = SqlHelper.ExecuteDataSet("select a.*,b.SQL,isnull(b.isReport,0) isReport from p_systemDlltabDetail a inner join p_systemdlltab b on a.UnionModule = b.DllCoid where a.tab='" + menuId + "' and a.isVisible=0 order by a.orderid").Tables[0];
|
||
// 明细列表没有数据,则获取报表明细配置,兼容旧版本
|
||
if (moduleDetailBottomTable == null || moduleDetailBottomTable.Rows.Count == 0)
|
||
{
|
||
moduleDetailBottomTable = SqlHelper.ExecuteDataSet("select * from p_systemDlltabDetail where tab='" + menuId + "' and isVisible=0 order by orderid").Tables[0];
|
||
}
|
||
XtraTabControl tabBottomMain = new XtraTabControl();
|
||
tabBottomMain.Dock = DockStyle.Fill;
|
||
foreach (DataRow row in moduleDetailBottomTable.Rows)
|
||
{
|
||
var unionModule = row["UnionModule"] + "";
|
||
var unionValue = row["UnionValue"] + "";
|
||
var detailName = row["detailName"] + "";
|
||
var autoRefresh = row["autoRefresh"] + "";
|
||
var idFileName = unionValue.Replace("{", "").Replace("}", "");
|
||
SqlParameter[] p =
|
||
{
|
||
new SqlParameter("@modid",SqlDbType.VarChar,20),
|
||
new SqlParameter("@operatorname",SqlDbType.VarChar,20)
|
||
};
|
||
p[0].Value = unionModule;
|
||
p[1].Value = OperatorName;
|
||
DataTable dtCol = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "[p_getBaseModuleField]", "temp", p).Tables[0];
|
||
|
||
XtraTabPage tabPage = new XtraTabPage();
|
||
tabPage.Text = detailName;
|
||
//tabPage.PageVisible = menuId != DLLCoid;
|
||
|
||
TabPageDetail p_tabPage = new TabPageDetail();
|
||
p_tabPage.pageText = detailName;
|
||
tabPage.Controls.Add(p_tabPage);
|
||
p_tabPage.Dock = DockStyle.Fill;
|
||
p_tabPage.BringToFront();
|
||
p_tabPage.gridList.SetColumns2(dtCol);
|
||
p_tabPage.Name = "tab";
|
||
DataTable dtMain = SqlHelper.ExecuteDataSet("select * from p_systemdlltab where dllcoid='" + unionModule + "'").Tables[0];
|
||
if (dtMain != null && dtMain.Rows.Count > 0)
|
||
{
|
||
p_tabPage.gridList.Sql = dtMain.Rows[0]["SQL"] + "";
|
||
p_tabPage.gridList.ModuleKey = unionModule;
|
||
p_tabPage.gridList.ModuleType = 1;
|
||
}
|
||
p_tabPage.DLLCoid = unionModule;
|
||
p_tabPage.FormText = detailName;
|
||
DataTable dtMainTag3 = SqlHelper.ExecuteDataSet("select top 1 fieldname from p_systemwordbooktab where tab='" + unionModule + "' order by orderid asc").Tables[0];
|
||
idFileName = dtMainTag3.Rows[0]["fieldname"] + "";
|
||
p_tabPage.objectId = idFileName; //关联字段Key
|
||
p_tabPage.OperatorId = OperatorId;
|
||
p_tabPage.OperatorName = OperatorName;
|
||
p_tabPage.Privilege = "0";
|
||
p_tabPage.objectValue = ""; // 关联字段值
|
||
p_tabPage.autoRefresh = "0"; // 初始化不刷新数据
|
||
p_tabPage.HasReport = moduleDetailBottomTable.Columns.Contains("isReport") ? Convert.ToBoolean(row["isReport"]) : true;
|
||
|
||
p_tabPage.gridList.gridView.Tag = moduleDetailBottomTable.Columns.Contains("SQL") ? row["SQL"] : row["detailSql"];
|
||
p_tabPage.gridList.Tag = row;
|
||
tabPage.Tag = p_tabPage;
|
||
|
||
tabBottomMain.TabPages.Add(tabPage);
|
||
plBottomMain.Controls.Add(tabBottomMain);
|
||
}
|
||
if (menuId == DLLCoid)
|
||
{
|
||
plBottomMain.Height = this.Height / 3; // 未设置高度,默认只显示30%高度
|
||
plBottomMain.Visible = moduleDetailBottomTable.Rows.Count != 0;
|
||
}
|
||
mButtomTabPages.Add(menuId, tabBottomMain);
|
||
}
|
||
/// <summary>
|
||
/// 设置底部表格数据
|
||
/// </summary>
|
||
/// <param name="row"></param>
|
||
private void SetBottomGridData(string menuId, string primaryKey, DataRow row)
|
||
{
|
||
foreach (XtraTabPage tab in mButtomTabPages[menuId].TabPages)
|
||
{
|
||
TabPageDetail tabPage = tab.Tag as TabPageDetail;
|
||
|
||
GridControlEx gc = tabPage.gridList;
|
||
DataRow drBottom = gc.Tag as DataRow;
|
||
string sql = gc.gridView.Tag + "";
|
||
string fieldName = primaryKey;
|
||
string fieldValue = row[fieldName] + "";
|
||
string detailSql = PubClass.ReqSqlParam(sql, OperatorId, OperatorName);
|
||
detailSql = PubClass.ReplaceWhereCond(PubClass.ReqSql(row, detailSql));
|
||
//string unionValue = row[(drBottom["unionValue"] + "").Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "").ToString()]+"";
|
||
//string unionField = (drBottom["unionValue"] + "").Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "");
|
||
string unionValue = row[fieldName] + "";
|
||
string unionField = (drBottom["unionValue"] + "").Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "");
|
||
tabPage.objectId = unionField;
|
||
tabPage.objectValue = unionValue;
|
||
DataTable dtMainTag = SqlHelper.ExecuteDataSet("select top 1 fieldname from p_systemwordbooktab where tab='" + drBottom["UnionModule"] + "" + "' and lower(fieldname)='" + unionField.ToLower() + "'").Tables[0];
|
||
if (dtMainTag.Rows.Count < 1)
|
||
{
|
||
unionField = tabPage.objectId;
|
||
}
|
||
//string unionField = tabPage.objectId;
|
||
// 列表模式
|
||
if (mRightGridDataMode == 1)
|
||
{
|
||
detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName);
|
||
}
|
||
else
|
||
{ // 报表明细模式
|
||
detailSql = PubClass.ReqSqlParam(detailSql, OperatorId, OperatorName);
|
||
List<string> paramList = PubClass.GetParamValue(detailSql);
|
||
foreach (string param in paramList)
|
||
{
|
||
string fileName = param.Replace("{", "").Replace("}", "").Replace("{", "").Replace("}", "");
|
||
if (dtColumns.Columns.Contains(fieldName))
|
||
{
|
||
detailSql = detailSql.Replace(param, row[fileName] + "");
|
||
}
|
||
}
|
||
}
|
||
gc.Sql = detailSql + " and " + unionField + " = '" + unionValue + "'";
|
||
tabPage.InitData(gc.Sql);
|
||
tab.Text = tabPage.pageText + "(" + gc.gridView.DataRowCount.ToString() + ")";
|
||
gc.gridView.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置明细数据
|
||
private void SetDetailData(string menuId, string primaryKey)
|
||
{
|
||
int[] rows = gcMain.gridView.GetSelectedRows();
|
||
if (rows != null && rows.Length > 0)
|
||
{
|
||
DataRow row = gcMain.gridView.GetDataRow(rows[0]);
|
||
|
||
// 验证按钮权限
|
||
this.HandleAddRowState(row);
|
||
this.HandleDelButtonState(row);
|
||
this.HandleEditRowState(row);
|
||
|
||
this.SetRightGridData(primaryKey, row); // 设置右侧表格数据
|
||
this.SetBottomGridData(menuId, primaryKey, row); // 设置底部表格数据
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 辅助方法
|
||
/// <summary>
|
||
/// 获取主键
|
||
/// </summary>
|
||
/// <param name="dllCoid"></param>
|
||
/// <returns></returns>
|
||
private string getParimaryKey(string menuid)
|
||
{
|
||
DataRow drRow = SqlHelper.ExecuteDataSet("select top 1 fieldname from P_systemwordbooktab where tab='" + menuid + "' order by orderid").Tables[0].Rows[0];
|
||
return drRow["fieldname"] + "";
|
||
}
|
||
#endregion
|
||
|
||
#region 切换Tab页
|
||
///// <summary>
|
||
///// 切换中
|
||
///// </summary>
|
||
///// <param name="sender"></param>
|
||
///// <param name="e"></param>
|
||
//private void tabTopMain_SelectedPageChanging(object sender, TabPageChangingEventArgs e)
|
||
//{
|
||
// XtraTabPage tabPage = tabTopMain.SelectedTabPage;
|
||
// if (tabPage != null && mButtomTabPages.Count > 0)
|
||
// {
|
||
// XtraTabControl detailTabPage = mButtomTabPages[tabPage.Tag + ""];
|
||
// if (detailTabPage != null && detailTabPage.TabPages.Count > 0)
|
||
// {
|
||
// detailTabPage.Visible = false;
|
||
// }
|
||
// plBottomMain.Visible = false;
|
||
// }
|
||
//}
|
||
///// <summary>
|
||
///// 切换后
|
||
///// </summary>
|
||
///// <param name="sender"></param>
|
||
///// <param name="e"></param>
|
||
//private void tabTopMain_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
|
||
//{
|
||
// XtraTabPage tabPage = tabTopMain.SelectedTabPage;
|
||
// if (tabPage != null && mButtomTabPages.Count > 0)
|
||
// {
|
||
// TabPageMaster mTabPage = tabPage.Controls[0] as TabPageMaster;
|
||
// XtraTabControl detailTabPage = mButtomTabPages[tabPage.Tag + ""];
|
||
// if (detailTabPage != null && detailTabPage.TabPages.Count > 0)
|
||
// {
|
||
// detailTabPage.Visible = true;
|
||
// plBottomMain.Visible = true;
|
||
// plBottomMain.Height = this.Height / 3;
|
||
// }
|
||
// else
|
||
// {
|
||
// plBottomMain.Visible = false;
|
||
// }
|
||
// }
|
||
//}
|
||
#endregion
|
||
|
||
#region 拖动回调
|
||
public void Drag_EventHandler(object sender, DragEventArgs e)
|
||
{
|
||
MessageBox.Show("类别修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
#endregion
|
||
|
||
#region 基础操作
|
||
/// <summary>
|
||
/// 导入
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnImprt_Click(object sender, EventArgs e)
|
||
{
|
||
//frmImport frm = new frmImport(gcMain.gridControl, mTableName);
|
||
string columnPrefix = PubClass.GetColumnPrefix(mTableName);
|
||
frmImport frm = new frmImport(gcMain, mTableName, "", "", OperatorId, OperatorName, columnPrefix);
|
||
frm.ShowDialog();
|
||
}
|
||
/// <summary>
|
||
/// 导出
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnExport_Click(object sender, EventArgs e)
|
||
{
|
||
PubClass.SaveXls(gcMain.gridControl);
|
||
}
|
||
/// <summary>
|
||
/// 帮助文档
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnHelp_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(DLLCoid))
|
||
{
|
||
XtraMessageBox.Show("物料编码不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
int id = 0;
|
||
object obj = SqlHelper.ExecuteScalar(CommandType.Text, "select dirid from P_fm_DirectoryTab where ParentId=3 and PID='" + DLLCoid + "'");
|
||
id = obj == null ? 0 : Convert.ToInt32(obj);
|
||
if (id == 0)
|
||
{
|
||
string sql = "insert into P_fm_DirectoryTab (sName,ParentId,creator,SpeciesNo,relationCode,PID) values('" + DLLCoid + "',3,1,'0201',0,'" + DLLCoid + "');select @@identity";
|
||
id = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sql));
|
||
}
|
||
string[] args =
|
||
{
|
||
FormText,
|
||
OperatorId,
|
||
OperatorName,
|
||
Privilege,
|
||
DLLCoid,
|
||
DLLCoid,
|
||
id+""
|
||
};
|
||
IForm form = PubUtil.LoadDllForm2("Lskj.Attachment.dll", args);
|
||
form.SubForm.ShowDialog();
|
||
}
|
||
/// <summary>
|
||
/// 添加数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnAdd_Click(object sender, EventArgs e)
|
||
{
|
||
string fieldsqlid = string.Empty;
|
||
string fieldsqlname = string.Empty;
|
||
string strTag = string.Empty;
|
||
string jsonData = string.Empty;
|
||
|
||
if (!string.IsNullOrEmpty(mSystemRow["AddDllName"] + ""))
|
||
{
|
||
if (mLeftType == 1)
|
||
{
|
||
if (tvLeft.GetTreeView.SelectedNode == null)
|
||
{
|
||
XtraMessageBox.Show("请选择类别", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
return;
|
||
}
|
||
if (tvLeft.GetTreeView.SelectedNode.Nodes.Count > 0)
|
||
{
|
||
XtraMessageBox.Show("请选择根级节点", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
return;
|
||
}
|
||
String bllNO = PubClass.GetBillNo(tvLeft.GetTreeView.SelectedNode.Tag + "", DLLCoid);
|
||
if (string.IsNullOrEmpty(bllNO))
|
||
{
|
||
XtraMessageBox.Show("请修改编码前缀", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
|
||
return;
|
||
}
|
||
fieldsqlid = tvLeft.GetTreeView.SelectedNode.Name;
|
||
fieldsqlname = tvLeft.GetTreeView.SelectedNode.Text;
|
||
strTag = tvLeft.GetTreeView.SelectedNode.Tag + "";
|
||
}
|
||
else if (mLeftType == 2)
|
||
{
|
||
int[] rows = GridViewLeft.GetSelectedRows();
|
||
if (rows.Length == 0)
|
||
{
|
||
XtraMessageBox.Show("请选择类别", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
return;
|
||
}
|
||
DataRow row = GridViewLeft.GetDataRow(rows[0]);
|
||
fieldsqlid = row[drLeft["fieldsqlid"] + ""] + "";
|
||
fieldsqlname = row[drLeft["fieldsqlname"] + ""] + "";
|
||
|
||
DataTable dtGcHeader = GridLeftEx.DataSource as DataTable;
|
||
if (dtGcHeader != null && dtGcHeader.Rows.Count > 0)
|
||
{
|
||
DataTable dtTemp = dtGcHeader.Clone();
|
||
dtTemp.ImportRow(row);
|
||
jsonData = dtTemp.ToJson();
|
||
}
|
||
}
|
||
|
||
string[] args = {
|
||
FormText,
|
||
OperatorId,
|
||
OperatorName,
|
||
Privilege,
|
||
DLLCoid,
|
||
"",
|
||
"",
|
||
"",
|
||
fieldsqlid,
|
||
fieldsqlname,
|
||
strTag,
|
||
"",
|
||
"",
|
||
"",
|
||
jsonData
|
||
};
|
||
IForm form = PubUtil.LoadDllForm(mSystemRow["AddDllName"] + "", args);
|
||
DialogResult result = form.SubForm.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
if (string.IsNullOrEmpty(BeforeSearchSQL))
|
||
{
|
||
InitData(PubClass.ReplaceWhereCond(BeforeSearchSQL));
|
||
}
|
||
else
|
||
{
|
||
Control[] ctr = pl_search.Controls.Find("btnCondSearch", true);
|
||
if ((ctr == null) || (ctr.Length < 1))
|
||
{
|
||
if (!string.IsNullOrEmpty(BeforeSearchSQL))
|
||
InitData(BeforeSearchSQL);
|
||
}
|
||
else
|
||
{
|
||
(ctr[0] as SimpleButton).PerformClick();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (mLeftType == 1)
|
||
{
|
||
TreeNode treeNode = tvLeft.GetTreeView.SelectedNode;
|
||
if (treeNode != null && treeNode.Nodes.Count > 0)
|
||
{
|
||
XtraMessageBox.Show("请选中末级节点!");
|
||
return;
|
||
}
|
||
}
|
||
AddRow(gcMain.gridView);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 删除事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnDelete_Click(object sender, EventArgs e)
|
||
{
|
||
string noDeleteIds = string.Empty;
|
||
int[] rowid = gcMain.gridView.GetSelectedRows();
|
||
if (rowid.Length == 0)
|
||
{
|
||
XtraMessageBox.Show("没有选择要删除数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
}
|
||
else
|
||
{
|
||
|
||
if (XtraMessageBox.Show("您确定要删除选中 " + rowid.Length + "条 记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
string ids = string.Empty;
|
||
foreach (int rid in rowid)
|
||
{
|
||
DataRow dr = gcMain.gridView.GetDataRow(rid);
|
||
//判断删除条件是否符合
|
||
Boolean canDelete = string.IsNullOrEmpty(mDeleteCond);
|
||
string tempCond = mDeleteCond;
|
||
if (!canDelete)
|
||
{
|
||
tempCond = PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName);
|
||
tempCond = PubClass.ReqSqlWhere(dr, tempCond);
|
||
canDelete = Convert.ToBoolean(Evaluator.Eval(tempCond));
|
||
}
|
||
if (canDelete)
|
||
{
|
||
//删除检查
|
||
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("@modid",SqlDbType.VarChar,20),
|
||
new SqlParameter("@keyvalue",SqlDbType.VarChar,40),
|
||
pMsg,
|
||
returnValue
|
||
};
|
||
param[0].Value = DLLCoid;
|
||
param[1].Value = dr[mPrimaryKey];
|
||
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_VerifyCanDelete", "baseSave", param);
|
||
string msg = pMsg.Value.ToString();
|
||
int rVaule = Convert.ToInt32(returnValue.Value.ToString());
|
||
if (rVaule == 1)
|
||
{
|
||
ids += "'" + dr[mPrimaryKey] + "',";
|
||
}
|
||
else
|
||
{
|
||
noDeleteIds += dr[mPrimaryKey] + " >> " + msg + "\n";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
noDeleteIds += dr[mPrimaryKey] + " >>不符删除合条件\n";
|
||
}
|
||
}
|
||
if (ids != string.Empty)
|
||
{
|
||
string sql = "delete from " + mSystemRow["SQLDT1"] + " where " + mPrimaryKey + " in(" + ids.Trim(',') + ")";
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
//InitData(MyNotBmpSql);
|
||
// 移除表格选中数据
|
||
gcMain.gridView.DeleteSelectedRows();
|
||
string strHint = "记录删除成功";
|
||
if (!string.IsNullOrEmpty(noDeleteIds))
|
||
strHint = strHint + ",但是发现如下记录不符合删除条件\n" + noDeleteIds;
|
||
XtraMessageBox.Show(strHint, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
SqlHelper.AddLogTab(DLLCoid, FormText + "-->删除", FormText + "[" + ids + "]", FormText, OperatorName);
|
||
}
|
||
else
|
||
{
|
||
string strHint = "没有符合删除条件的记录";
|
||
if (!string.IsNullOrEmpty(noDeleteIds))
|
||
strHint = strHint + ",发现如下记录不符合删除条件\n" + noDeleteIds;
|
||
XtraMessageBox.Show(strHint, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 保存
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (gridRequired())
|
||
{
|
||
try
|
||
{
|
||
GridAdapter.Update(gcMain.gridControl.DataSource as DataTable);
|
||
}
|
||
catch (DBConcurrencyException dce)
|
||
{
|
||
// 并发异常
|
||
XtraMessageBox.Show("数据已更新,请刷新后重试.");
|
||
return;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex.Message.IndexOf("ix", StringComparison.OrdinalIgnoreCase) != -1)
|
||
{
|
||
MessageBox.Show("系统检测到录入信息重复,请检查", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
return;
|
||
}
|
||
}
|
||
XtraMessageBox.Show("修改成功");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 打印
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnPrint_Click(object sender, EventArgs e)
|
||
{
|
||
PubClass.Preview(gcMain.gridControl);
|
||
}
|
||
/// <summary>
|
||
/// 查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnCondSearch_Click(object sender, EventArgs e)
|
||
{
|
||
mIsSearch = true; // 设置当前查询模式为全部数据查询
|
||
SearchData();
|
||
}
|
||
/// <summary>
|
||
/// 表格颜色
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void gridView_RowStyle(object sender, RowStyleEventArgs e)
|
||
{
|
||
if (e.RowHandle >= 0)
|
||
{
|
||
DataRow row = gcMain.gridView.GetDataRow(e.RowHandle);
|
||
string cond = string.Empty;
|
||
string color = string.Empty;
|
||
string forecolor = string.Empty;
|
||
foreach (DataRow dr in mGridColorList.Rows)
|
||
{
|
||
List<string> condition = PubClass.GetParamValue(dr["condition"] + "");
|
||
cond = dr["condition"] + "";
|
||
foreach (string item in condition)
|
||
{
|
||
string filedName = item.Replace("{", "").Replace("}", "");
|
||
cond = cond.Replace(item, row[filedName] + "");
|
||
}
|
||
cond = PubClass.SqlToCode(cond);
|
||
color = dr["backcolor"] + "";
|
||
forecolor = dr["forcecolor"] + "";
|
||
|
||
string obj = Evaluator.Eval(cond) + "";
|
||
if (obj.IndexOf("true", StringComparison.OrdinalIgnoreCase) != -1)
|
||
{
|
||
if (!string.IsNullOrEmpty(color))
|
||
{
|
||
Color color1 = ColorTranslator.FromHtml(color);
|
||
e.Appearance.BackColor = color1;
|
||
}
|
||
if (!string.IsNullOrEmpty(forecolor))
|
||
{
|
||
Color foreColor = ColorTranslator.FromHtml(forecolor);
|
||
e.Appearance.ForeColor = foreColor;
|
||
|
||
}
|
||
FontStyle fst = new FontStyle();
|
||
if (dr["ifBold"] + "" == "1")
|
||
{
|
||
fst = fst | FontStyle.Bold;
|
||
}
|
||
if (dr["ifItalic"] + "" == "1")
|
||
{
|
||
fst = fst | FontStyle.Italic;
|
||
}
|
||
if (dr["ifStrickOut"] + "" == "1")
|
||
{
|
||
fst = fst | FontStyle.Strikeout;
|
||
}
|
||
if (dr["ifUnderLine"] + "" == "1")
|
||
{
|
||
fst = fst | FontStyle.Underline;
|
||
}
|
||
e.Appearance.Font = new Font(e.Appearance.Font, fst);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 表格编辑
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void gridView_ShowingEditor(object sender, CancelEventArgs e)
|
||
{
|
||
e.Cancel = !btnSave.Enabled;
|
||
}
|
||
/// <summary>
|
||
/// 查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void txtKey_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
this.btnCondSearch.PerformClick();
|
||
}
|
||
#endregion
|
||
|
||
#region 左侧树、表格点击加载数据
|
||
/// <summary>
|
||
/// 左侧树点击
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public void LeftTreeAfterSelect(object sender, TreeViewEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Action == TreeViewAction.ByMouse)
|
||
{
|
||
mIsSearch = false; // 设置当前查询模式为部分数据查询
|
||
string strWhere = " and " + drLeft["fieldname"] + " like '" + e.Node.Name + "%'";
|
||
string sql = PubClass.ReplaceWhereCond(mSystemRow["SQL"] + "") + strWhere;
|
||
InitData(sql);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 左侧表格点击
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public void LeftGridCellClick(object sender, RowCellClickEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
mIsSearch = false; // 设置当前查询模式为部分数据查询
|
||
DataRow row = (sender as GridView).GetDataRow(e.RowHandle);
|
||
string key = drLeft["fieldname"] + "";
|
||
string value = row[drLeft["fieldsqlid"] + ""] + "";
|
||
InitData(PubClass.ReplaceWhereCond(mSystemRow["SQL"] + "") + " and " + key + " = '" + value + "' ");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 修改数据
|
||
private void gridView_DoubleClick(object sender, EventArgs e)
|
||
{
|
||
if (!string.IsNullOrEmpty(mSystemRow["AddDllName"] + ""))
|
||
{
|
||
bool isReflash = UpdateModel();
|
||
if (isReflash)
|
||
{
|
||
//SearchCondData();
|
||
if (!string.IsNullOrEmpty(BeforeSearchSQL))
|
||
{
|
||
InitData(BeforeSearchSQL);
|
||
}
|
||
else
|
||
{
|
||
Control[] ctr = pl_search.Controls.Find("btnCondSearch", true);
|
||
if ((ctr == null) || (ctr.Length < 1))
|
||
{
|
||
if (string.IsNullOrEmpty(BeforeSearchSQL))
|
||
{
|
||
if (mSeearchMode == 1)
|
||
{
|
||
string sqlValue = mccTop.SetSearchSqlValue();
|
||
if (!string.IsNullOrEmpty(sqlValue))
|
||
{
|
||
InitData(sqlValue);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
btnCondSearch_Click(null, null);
|
||
}
|
||
}
|
||
else
|
||
InitData(BeforeSearchSQL);
|
||
}
|
||
else
|
||
{
|
||
(ctr[0] as SimpleButton).PerformClick();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public bool UpdateModel()
|
||
{
|
||
int[] rows = gcMain.gridView.GetSelectedRows();
|
||
if (rows.Length > 0)
|
||
{
|
||
DataRow dr = gcMain.gridView.GetDataRow(rows[0]);
|
||
//判断修改条件是否符合
|
||
Boolean canModify = string.IsNullOrEmpty(mModifyCond);
|
||
if (mNeedModify)
|
||
{
|
||
string tempCond = mModifyCond;
|
||
if (!canModify)
|
||
{
|
||
tempCond = PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName);
|
||
tempCond = PubClass.ReqSqlWhere(dr, tempCond);
|
||
canModify = tempCond.Trim() == "" ? true : Convert.ToBoolean(Evaluator.Eval(tempCond));
|
||
}
|
||
}
|
||
else
|
||
canModify = false;
|
||
|
||
string productId = dr[mPrimaryKey].ToString();
|
||
string[] args = {
|
||
FormText,
|
||
OperatorId,
|
||
OperatorName,
|
||
Privilege,
|
||
DLLCoid,
|
||
"",
|
||
Convert.ToInt32( !canModify).ToString(),
|
||
productId,
|
||
"",
|
||
"",
|
||
""
|
||
};
|
||
IForm form = PubUtil.LoadDllForm(mSystemRow["AddDllName"] + "", args);
|
||
DialogResult dialogResult = form.SubForm.ShowDialog();
|
||
}
|
||
return true;
|
||
}
|
||
#endregion
|
||
|
||
#region 添加数据
|
||
/// <summary>
|
||
/// 添加行
|
||
/// </summary>
|
||
/// <param name="view"></param>
|
||
protected void AddRow(DevExpress.XtraGrid.Views.Grid.GridView view)
|
||
{
|
||
int prevDataRowIndex = view.GetFocusedDataSourceRowIndex();
|
||
view.AddNewRow();
|
||
//默认值
|
||
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 (defaultValue != "")
|
||
{
|
||
view.SetRowCellValue(view.FocusedRowHandle, item, defaultValue);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//关键字段赋值
|
||
if (mLeftType == 2)
|
||
{
|
||
int[] rows = GridViewLeft.GetSelectedRows();
|
||
if (rows.Length > 0)
|
||
{
|
||
DataRow row = GridViewLeft.GetDataRow(rows[0]);
|
||
GridColumn tmpcol = gcMain.gridView.Columns[drLeft["fieldname"] + ""];
|
||
view.SetRowCellValue(gcMain.gridView.FocusedRowHandle, tmpcol, row[drLeft["fieldsqlid"] + ""]);
|
||
view.UpdateCurrentRow();
|
||
view.ShowEditor();
|
||
}
|
||
}
|
||
if (mLeftType == 1)
|
||
{
|
||
TreeNode tn = tvLeft.GetTreeView.SelectedNode;
|
||
GridColumn tmpcol = gcMain.gridView.Columns[drLeft["fieldname"] + ""];
|
||
view.SetRowCellValue(gcMain.gridView.FocusedRowHandle, tmpcol, tn.Name);
|
||
view.UpdateCurrentRow();
|
||
view.ShowEditor();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存数据
|
||
/// <summary>
|
||
/// 表格必须录入验证
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private bool gridRequired()
|
||
{
|
||
DataTable dtBillItem = gcMain.gridControl.DataSource as DataTable;
|
||
DataColumnCollection dtBillRow = dtBillItem.Columns;
|
||
GridView gridView = gcMain.gridView;
|
||
GridColumnCollection gridColumns = gridView.Columns;
|
||
|
||
foreach (DataRow drGrid in dtBillItem.Rows)
|
||
{
|
||
foreach (DataRow dr in mNullableFields)
|
||
{
|
||
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;
|
||
}
|
||
#endregion
|
||
|
||
#region 查询数据
|
||
/// <summary>
|
||
/// 查询所有数据
|
||
/// </summary>
|
||
private void SearchData()
|
||
{
|
||
string field = cbField.SelectedValue + "";
|
||
string strWhere = " ";
|
||
if (mLeftType == 1)
|
||
{
|
||
foreach (TreeNode tn in tvLeft.GetTreeView.Nodes)
|
||
GetCheckedState(tn);
|
||
}
|
||
if (!string.IsNullOrEmpty(field))
|
||
strWhere += " and (dbo.P_getpy(" + field + ") like '%" + txtKey.Text + "%' or " + field + " like '%" + txtKey.Text + "%')";
|
||
if (!string.IsNullOrEmpty(mTreeTags))
|
||
strWhere += " and " + drLeft["fieldname"] + " in (" + mTreeTags.Trim(',') + ")";
|
||
InitData(PubClass.ReplaceWhereCond(mSystemRow["SQL"] + "") + strWhere);
|
||
}
|
||
/// <summary>
|
||
/// 查询数据(按当前模式,树点击or表格点击or点击查询按钮)
|
||
/// </summary>
|
||
private void SearchCondData()
|
||
{
|
||
string sqlValue = mSystemRow["SQL"] + "";
|
||
// 假如为树形结构,并且为点击树查询数据
|
||
if (mLeftType == 1 && !mIsSearch)
|
||
{
|
||
TreeNode treeNode = tvLeft.GetTreeView.SelectedNode;
|
||
if (treeNode != null)
|
||
InitData(PubClass.ReplaceWhereCond(sqlValue) + " and " + mPrimaryKey + " like '" + treeNode.Name + "%' ");
|
||
else
|
||
InitData(sqlValue);
|
||
}
|
||
// 假如左侧为表格数据,并且为点击表格查询数据
|
||
else if (mLeftType == 2 && !mIsSearch)
|
||
{
|
||
int[] rows = GridViewLeft.GetSelectedRows();
|
||
if (rows.Length == 0)
|
||
return;
|
||
DataRow row = GridViewLeft.GetDataRow(rows[0]);
|
||
InitData(PubClass.ReplaceWhereCond(sqlValue) + " and " + mPrimaryKey + " like '" + row[drLeft["fieldsqlid"] + ""] + "%' ");
|
||
}
|
||
else
|
||
{
|
||
// 查询所有数据
|
||
InitData(sqlValue);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 辅助方法
|
||
/// <summary>
|
||
/// 加载表格列头
|
||
/// </summary>
|
||
/// <param name="tab"></param>
|
||
public void InitColumns()
|
||
{
|
||
SqlParameter[] p =
|
||
{
|
||
new SqlParameter("@modid",SqlDbType.VarChar,20),
|
||
new SqlParameter("@operatorname",SqlDbType.VarChar,20)
|
||
};
|
||
p[0].Value = DLLCoid;
|
||
p[1].Value = OperatorName;
|
||
dtColumns = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "[p_getBaseModuleField]", "temp", p).Tables[0];
|
||
mNullableFields = dtColumns.Rows.OfType<DataRow>().Where(x => x["tagid"] + "" == "1").ToArray();
|
||
gcMain.ModuleKey = DLLCoid;
|
||
gcMain.ModuleType = 1;
|
||
gcMain.SetColumns2(dtColumns);
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void InitMenu()
|
||
{
|
||
GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", gcMain.gridControl);
|
||
gm.DirId = mSystemRow["dirid"] + "";
|
||
gm.filedKey = mPrimaryKey;
|
||
gm.BindGridMenuWQ(DLLCoid);
|
||
gm.OnGridMenuClickRefreshData += new EventHandler(gm_OnGridMenuClickRefreshData);
|
||
}
|
||
/// <summary>
|
||
/// 初始化数据
|
||
/// </summary>
|
||
/// <param name="sqlValue"></param>
|
||
public void InitData(string sqlValue)
|
||
{
|
||
HandleBmp(sqlValue);
|
||
int oldRowHandle = (gcMain.gridControl.MainView as GridView).FocusedRowHandle;
|
||
BeforeSearchSQL = sqlValue;
|
||
//这个绑定数据源
|
||
GridAdapter = SqlHelper.ExecuteAdapter(CommandType.Text, sqlValue);
|
||
if (GridDataSet != null && GridDataSet.Tables.Count > 0)
|
||
GridDataSet.Clear();
|
||
GridAdapter.Fill(GridDataSet);
|
||
SqlCommandBuilder cb = new SqlCommandBuilder(GridAdapter);
|
||
gcMain.gridControl.DataSource = GridDataSet.Tables[0];
|
||
(gcMain.gridControl.MainView as GridView).ClearSelection();
|
||
(gcMain.gridControl.MainView as GridView).FocusedRowHandle = oldRowHandle;
|
||
(gcMain.gridControl.MainView as GridView).SelectRow(oldRowHandle);
|
||
}
|
||
/// <summary>
|
||
/// 顶部查询条件(保留之前的按列查询)
|
||
/// </summary>
|
||
public void SearchCreateTopControl()
|
||
{
|
||
string sql = string.Format("exec p_getControlLocation '{0}','{1}','{2}'", mSystemRow["condKey"], DLLCoid, OperatorName);
|
||
DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
mSeearchMode = 1;
|
||
string condSql = string.Format("select * from p_systembillsourcecond where formKey='{0}'", mSystemRow["condKey"]);
|
||
mccTop.LoginId = OperatorId;
|
||
mccTop.LoginName = OperatorName;
|
||
mccTop.SearchSql = PubClass.ReplaceWhereCond(mSystemRow["SQL"] + "");
|
||
mccTop.ctr = pl_search;
|
||
mccTop.tvLeft = tvLeft;
|
||
mccTop.tvLeftDataRow = drLeft;
|
||
mccTop.gce = gcMain.gridControl;
|
||
mccTop.RememberRow = true;
|
||
mccTop.dllType = mLeftType;
|
||
mccTop.condDt = SqlHelper.ExecuteDataSet(condSql).Tables[0];
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
CreateControlModel cm = new CreateControlModel();
|
||
cm.dt = dt;
|
||
cm.ctr = pl_search;
|
||
cm.loginid = OperatorId;
|
||
cm.loginname = OperatorName;
|
||
int height = mccTop.CreateControlByModel(cm);
|
||
pl_search.Height = height;
|
||
Control[] ctl = pl_search.Controls.Find("btnCondSearch", true);
|
||
if ((ctl != null) && (ctl.Length > 0))
|
||
{
|
||
(ctl[0] as SimpleButton).Width = 72;
|
||
}
|
||
}
|
||
if (mSystemRow["searchEnable"] + "" == "1")
|
||
{
|
||
string sqlValue = mccTop.SetSearchSqlValue();
|
||
if (!string.IsNullOrEmpty(sqlValue))
|
||
{
|
||
//InitData(sqlValue);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
mSeearchMode = 2;
|
||
// 假如未配置查询条件,则显示之前的下拉查询条件
|
||
label1.Visible = true;
|
||
cbField.Visible = true;
|
||
txtKey.Visible = true;
|
||
btnCondSearch.Visible = true;
|
||
if (mSystemRow["searchEnable"] + "" == "1")
|
||
btnCondSearch_Click(null, null);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 处理图片
|
||
/// </summary>
|
||
/// <param name="sql"></param>
|
||
private string HandleBmp(string sql)
|
||
{
|
||
string notBmpSql = sql;
|
||
DataTable dtBmps = SqlHelper.ExecuteDataSet("select fieldname from P_systemwordbooktab where tab='" + DLLCoid + "' and fieldSqlTag=99").Tables[0];
|
||
foreach (DataRow row in dtBmps.Rows)
|
||
{
|
||
string fieldName = row["fieldname"] + "";
|
||
notBmpSql = notBmpSql.Replace(" ", "-").Replace("-", "").Replace(", ", ",").Replace(" ,", ",");
|
||
notBmpSql = notBmpSql.Replace("," + fieldName + ",", ",").Replace("," + fieldName, " ");
|
||
}
|
||
return sql;
|
||
}
|
||
/// <summary>
|
||
/// 处理删除按钮
|
||
/// </summary>
|
||
private void HandleDelButtonState(DataRow dr)
|
||
{
|
||
try
|
||
{
|
||
string tempCond = mDeleteCond;
|
||
bool canDel = string.IsNullOrEmpty(mDeleteCond);
|
||
if (!string.IsNullOrEmpty(tempCond))
|
||
{
|
||
tempCond = PubClass.ReqSqlWhere(dr, PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
|
||
canDel = Convert.ToBoolean(Evaluator.Eval(tempCond));
|
||
}
|
||
btnDelete.Enabled = canDel && mSystemRow["deleteEnable"] + "" == "1";
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 验证是否可以编辑行
|
||
/// </summary>
|
||
/// <param name="dr"></param>
|
||
private void HandleEditRowState(DataRow dr)
|
||
{
|
||
try
|
||
{
|
||
string tempCond = mModifyCond;
|
||
bool canEdit = string.IsNullOrEmpty(mModifyCond);
|
||
if (!string.IsNullOrEmpty(tempCond))
|
||
{
|
||
tempCond = PubClass.ReqSqlWhere(dr, PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
|
||
canEdit = Convert.ToBoolean(Evaluator.Eval(tempCond));
|
||
}
|
||
btnSave.Enabled = canEdit && mSystemRow["modifyEnable"] + "" == "1";
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 验证添加按钮权限
|
||
/// </summary>
|
||
/// <param name="dr"></param>
|
||
private void HandleAddRowState(DataRow dr)
|
||
{
|
||
try
|
||
{
|
||
string tempCond = mAddCond;
|
||
bool canAdd = string.IsNullOrEmpty(mAddCond);
|
||
if (!string.IsNullOrEmpty(tempCond))
|
||
{
|
||
tempCond = PubClass.ReqSqlWhere(dr, PubClass.ReqSqlParam(tempCond, OperatorId, OperatorName));
|
||
canAdd = Convert.ToBoolean(Evaluator.Eval(tempCond));
|
||
}
|
||
btnAdd.Enabled = canAdd && mSystemRow["addEnable"] + "" == "1";
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 处理表格计算
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void gridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
||
{
|
||
if (inSummary) return;
|
||
inSummary = true;
|
||
try
|
||
{
|
||
DataRow gvRow = gcMain.gridView.GetDataRow(e.RowHandle);
|
||
foreach (DataRow row in mGridSum.Rows)
|
||
{
|
||
string calcExpr = row["calcExpr"] + "";
|
||
if (e.Column.FieldName != row["fieldName"] + "")
|
||
{
|
||
List<string> listParam = PubClass.GetParamValue(calcExpr);
|
||
foreach (string str in listParam)
|
||
{
|
||
string filed = str.Replace("{", "").Replace("}", "");
|
||
string filedValue = gvRow[filed] + "";
|
||
if (string.IsNullOrEmpty(filedValue))
|
||
filedValue = "0";
|
||
calcExpr = calcExpr.Replace(str, filedValue + "");
|
||
}
|
||
calcExpr = calcExpr.Replace("=", "==").Replace("<>", "!=").Replace("and", "&&").Replace("or", "|");
|
||
string result = Evaluator.Eval(calcExpr) + "";
|
||
gcMain.gridView.SetRowCellValue(e.RowHandle, gcMain.gridView.Columns[row["fieldName"] + ""], Math.Round(double.Parse(result), 2, MidpointRounding.AwayFromZero));
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
inSummary = false;
|
||
}
|
||
/// <summary>
|
||
/// 获取树选中节点
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private string GetTreeCheck()
|
||
{
|
||
mTreeTags = string.Empty;
|
||
foreach (TreeNode item in tvLeft.GetTreeView.Nodes)
|
||
{
|
||
GetCheckedState(item);
|
||
}
|
||
return mTreeTags;
|
||
}
|
||
/// <summary>
|
||
/// 选中节点之后,选中节点的所有子节点
|
||
/// </summary>
|
||
/// <param name="currNode"></param>
|
||
/// <param name="state"></param>
|
||
private void GetCheckedState(TreeNode currNode)
|
||
{
|
||
if (currNode.Checked)
|
||
mTreeTags += "" + currNode.Name + ",";
|
||
TreeNodeCollection nodes = currNode.Nodes;
|
||
if (nodes.Count > 0)
|
||
{
|
||
foreach (TreeNode tn in nodes)
|
||
{
|
||
if (tn.Checked)
|
||
mTreeTags += "'" + tn.Name + "',";
|
||
GetCheckedState(tn);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 执行右键菜单后刷新表格数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void gm_OnGridMenuClickRefreshData(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(BeforeSearchSQL))
|
||
{
|
||
if (mSeearchMode == 1)
|
||
{
|
||
string sqlValue = mccTop.SetSearchSqlValue();
|
||
if (!string.IsNullOrEmpty(sqlValue))
|
||
{
|
||
InitData(sqlValue);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
btnCondSearch_Click(null, null);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
InitData(BeforeSearchSQL);
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|