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.Model;
using Lskj.Core;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList.Nodes;
using Lskj.Business.Impl;
using DevExpress.XtraTreeList;
using Lskj.Control.Model;
using DevExpress.XtraEditors;
using DevExpress.XtraBars;
using System.Collections.Specialized;
namespace Lskj.Control
{
public partial class FrmAutoSqlLoad : BaseForm
{
///
/// 关联字段所在控件
///
private System.Windows.Forms.Control ClickControl;
///
/// 是否启用颜色改变提示
///
private bool IsChangeItemColor;
///
/// 右键菜单
///
private DevExpress.XtraBars.PopupMenu popupMenu;
///
/// 右侧panel内表格
///
/// The left grid view object.
public Dictionary gridControlDic = new Dictionary();
public OrderedDictionary OrderGridControlDic = new OrderedDictionary();//排序字典
///
/// 底部分组控件内
///
/// The left grid view object.
public Dictionary groupControlDic = new Dictionary();
public OrderedDictionary OrderGroupControlDic = new OrderedDictionary();//排序字典
///
/// 左侧树结构对象
///
/// The TreeView object.
//public TreeViewEx LeftTreeViewObj { get { return this.leftTree; } }
///
/// 中心表格对象
///
/// The left grid view object.
public GridControlEx MainGridViewObj { get { return this.gcMain; } }
///
/// 系统模块实体对象
///
/// The system model.
public ModuleModel SysModel { get; private set; }
///
/// 显示sql
///
/// The system model.
public string EditText;
///
/// sql列部分
///
/// The system model.
public string sqlColText;
///
/// sql关联部分
///
/// The system model.
public string sqlJoinText;
public FrmAutoSqlLoad()
{
InitializeComponent();
}
#region 方法
#region 窗口加载
///
/// 说明:窗口加载
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
protected override void OnLoad(EventArgs e)
{
this.CoumnGroup.AllowDrop = true;//允许拖拽
this.btn_Produce.Click += OnBtn_Produce_Click;
this.btn_determine.Click += OnBtn_determine_Click;
this.SizeChanged += OnFrmAutoSqlLoad_SizeChanged;
this.topSplitContainerControl.SplitterPositionChanged += OnTopSplitContainerControl_SplitterPositionChanged;
this.clearBtn.Click += OnClearBtn_Click;//清除按钮点击
popupMenu = new DevExpress.XtraBars.PopupMenu(barManager);//右键菜单
BarButtonItem barButtonItemFull = new DevExpress.XtraBars.BarButtonItem();
barButtonItemFull.Caption = "全连接";
barButtonItemFull.Name = "join";
BarButtonItem barButtonItemLeft = new DevExpress.XtraBars.BarButtonItem();
barButtonItemLeft.Caption = "左连接";
barButtonItemLeft.Name = "left join";
BarButtonItem barButtonItemRight = new DevExpress.XtraBars.BarButtonItem();
barButtonItemRight.Caption = "右连接";
barButtonItemRight.Name = "right join";
popupMenu.AddItems(new BarButtonItem[] { barButtonItemFull, barButtonItemLeft, barButtonItemRight });
for (int i = 0; i < popupMenu.ItemLinks.Count; i++)
{
popupMenu.ItemLinks[i].BeginGroup = true;//设置分割条
popupMenu.ItemLinks[i].Item.ItemClick += OnItem_ItemClick;
}
InitializationTreeList();
}
#endregion
#region 初始化左侧树
///
/// 说明:初始化左侧树
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
private void InitializationTreeList()
{
creatTreeListControl();
this.leftTree.OptionsView.ShowCheckBoxes = true;
this.leftTree.OptionsBehavior.Editable = false;
string sqlValue = @"
WITH tmenu(id,MenuCaption,ParentId,menuid,SubSysId,level)
as
(
SELECT convert(varchar(50), menu.SubSysId)+'_'+ MenuStruct id,MenuCaption,CONVERT(varchar(50), -CONVERT(int, menu.SubSysId)) ParentId,menu.menuid,menu.SubSysId,1 level FROM p_formmenuconfigtab menu
inner join P_SubSystemTab sub on menu.SubSysId=sub.SubSysId and LEN(menustruct)=2
UNION ALL
SELECT convert(varchar(50), a.SubSysId)+'_'+A.MenuStruct id, A.MenuCaption,CONVERT(varchar(50),convert(varchar(50), a.SubSysId)+'_'+ SUBSTRING(a.MenuStruct,1,case when LEN(a.MenuStruct)>2 then LEN(a.MenuStruct)-2 else 0 end)) ParentId,a.MenuId,a.SubSysId ,b.level+1 FROM p_formmenuconfigtab A,tmenu b
where LEN(a.MenuStruct)>2 and convert(varchar(50), a.SubSysId)+'_'+ SUBSTRING(a.MenuStruct,1,case when LEN(a.MenuStruct)>2 then LEN(a.MenuStruct)-2 else 0 end) = b.id and a.SubSysId=b.SubSysId
)
select tm.MenuId, lm.id id,tm.urlparams menucode,tm.MenuCaption,tm.DllFileName library,lm.ParentId parentId,tm.SubSysId, lm.level,'' readflag, '' writeflag
from tmenu lm
left join p_formmenuconfigtab tm on lm.menuid=tm.menuid
union all
select '' menuid,convert(varchar(10), -SubSysId) MenuStruct ,'' menucode,subsysname MenuCaption,'' library,'' parentid,SubSysId,0 level,'' editflag, '' Readflag from P_SubSystemTab
ORDER BY SubSysId,id";
DataTable treeTable = SqlHelper.ExecuteDataTable(sqlValue);
DataTable dataTable = new DataTable();
dataTable.Columns.Add("id");
dataTable.Columns.Add("parentId");
dataTable.Columns.Add("Caption");
dataTable.Columns.Add("MenuId");
List idlist = new List();
for (int i = 0; i < treeTable.Rows.Count; i++)
{
DataRow newRow = dataTable.NewRow();
newRow["parentId"] = treeTable.Rows[i]["parentId"];
newRow["Caption"] = treeTable.Rows[i]["MenuCaption"];
newRow["MenuId"] = treeTable.Rows[i]["menucode"];
if (idlist.Contains(treeTable.Rows[i]["id"] + ""))
{
newRow["id"] = treeTable.Rows[i]["id"] + "" + '-' + i;
idlist.Add(newRow["id"] + "");
}
else
{
newRow["id"] = treeTable.Rows[i]["id"];
idlist.Add(newRow["id"] + "");
}
dataTable.Rows.Add(newRow);
}
this.leftTree.DataSource = dataTable;
this.leftTree.KeyFieldName = "id";
this.leftTree.ParentFieldName = "parentId";
this.leftTree.Columns[0].OptionsColumn.AllowEdit = false;
this.leftTree.Columns[1].OptionsColumn.AllowEdit = false;
this.leftTree.Columns[1].Visible = false;
this.leftTree.ExpandToLevel(0);
this.leftTree.OptionsBehavior.AllowIndeterminateCheckState = true;
this.leftTree.AfterCheckNode += OnLeftTree_AfterCheckNode;
this.leftTree.BeforeCheckNode += OnLeftTree_BeforeCheckNode;
}
#endregion
#region 动态创建TreeList的Column
///
/// 说明:动态创建TreeList的Column
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
private void creatTreeListControl()
{
TreeListColumn treeListColumnName = new TreeListColumn();
treeListColumnName.Caption = "系统名称";
treeListColumnName.FieldName = "Caption";
treeListColumnName.MinWidth = 38;
treeListColumnName.Visible = true;
treeListColumnName.VisibleIndex = 0;
treeListColumnName.Width = 400;
TreeListColumn treeListColumnMenuId = new TreeListColumn();
treeListColumnMenuId.Caption = "菜单id";
treeListColumnMenuId.FieldName = "MenuId";
treeListColumnMenuId.Visible = true;
treeListColumnMenuId.VisibleIndex = 1;
this.leftTree.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] {
treeListColumnName,
treeListColumnMenuId,
});
this.leftTree.Nodes.Clear();
this.leftTree.Refresh();
}
#endregion
#region 子节点状态改变时
///
/// 说明:子节点状态改变时
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
private void SetCheckedChildNodes(TreeListNode node, CheckState check)
{
for (int i = 0; i < node.Nodes.Count; i++)
{
node.Nodes[i].CheckState = check;
SetCheckedChildNodes(node.Nodes[i], check);
}
}
#endregion
#region 父节点状态改变时
///
/// 说明:父节点状态改变时
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
private void SetCheckedParentNodes(TreeListNode node, CheckState check)
{
if (node.ParentNode != null)
{
bool b = false;
CheckState state;
for (int i = 0; i < node.ParentNode.Nodes.Count; i++)
{
state = (CheckState)node.ParentNode.Nodes[i].CheckState;
if (!check.Equals(state))
{
b = !b;
break;
}
}
node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
SetCheckedParentNodes(node.ParentNode, check);
}
}
#endregion
#region 添加列至sql语句
private void AddColStrToSql()
{
this.ResGridInfText.Text = "";
//this.sqlRichTextBox.Text = "select ";
this.sqlColText = "select ";
this.sqlJoinText = string.Format("\r\nfrom {0}", ((((OrderGroupControlDic[0] as GroupBox).Tag as OrderedDictionary)[0] as SiftColControl.DragItem).ItemLable.Tag as GridView).Columns[0].FieldName);
for (int i = 0; i < OrderGroupControlDic.Count; i++)
{
GroupBox NGroupBox = OrderGroupControlDic[i] as GroupBox;
OrderedDictionary ItemsDic = NGroupBox.Tag as OrderedDictionary;
for (int j = 0; j < ItemsDic.Count; j++)
{
//DataRow[] rows = new DataRow[((ItemsDic[i] as SiftColControl.DragItem).Tag as OrderedDictionary).Count];
//((ItemsDic[i] as SiftColControl.DragItem).Tag as OrderedDictionary).Values.CopyTo(rows, 0);
//DataRow row = rows[0];
string colStrBefor = (ItemsDic[j] as SiftColControl.DragItem).ItemLable.Text;
string colStr = colStrBefor.Substring(colStrBefor.IndexOf('(') + 1, colStrBefor.IndexOf(')') - colStrBefor.IndexOf('(') - 1);
string colChineseStr = colStrBefor.Substring(0, colStrBefor.IndexOf('('));
this.sqlColText += string.Format("{0} {1},\r\n", colStr, colChineseStr);
}
}
this.sqlRichTextBox.Text = this.sqlColText.Substring(0, this.sqlColText.LastIndexOf(',')) + this.sqlJoinText;
}
#endregion
#endregion
#region 事件
#region 点击树表格节点前事件
//
/// 说明:点击树表格节点前事件
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
private void OnLeftTree_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e)
{
e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);
}
#endregion
#region 点击树表格节点后事件
//
/// 说明:点击树表格节点后事件
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
private void OnLeftTree_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{
WaitForm.ShowForm();
SetCheckedChildNodes(e.Node, e.Node.CheckState);
SetCheckedParentNodes(e.Node, e.Node.CheckState);
TreeList treelist = (TreeList)sender;
foreach (TreeListNode checkNode in treelist.GetAllCheckedNodes())
{
if (checkNode.Nodes.Count == 0 && !gridControlDic.Keys.Contains(checkNode.Id))
{
GridControlEx gridControlEx = new GridControlEx();
gridControlEx.GridView.Tag = checkNode.Id;
DataTable rightListData = new DataTable();
DataTable rightListBoxTab = new DataTable();
if (SqlHelper.ExecuteDataTable(string.Format("select * from p_systemwordbooktab where tab='{0}'", checkNode.GetValue("MenuId"))).Rows.Count != 0)
rightListBoxTab = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemwordbooktab where tab='{0}'", checkNode.GetValue("MenuId")));
else if (SqlHelper.ExecuteDataTable(string.Format("select * from p_systembillDetail where typecode='{0}'", checkNode.GetValue("MenuId"))).Rows.Count != 0)
rightListBoxTab = SqlHelper.ExecuteDataTable(string.Format("select * from p_systembillDetail where typecode='{0}'", checkNode.GetValue("MenuId")));
else if (SqlHelper.ExecuteDataTable(string.Format("select * from p_systembillstepgrid where typecode='{0}'", checkNode.GetValue("MenuId"))).Rows.Count != 0)
rightListBoxTab = SqlHelper.ExecuteDataTable(string.Format("select * from p_systembillstepgrid where typecode='{0}'", checkNode.GetValue("MenuId")));
else if (SqlHelper.ExecuteDataTable(string.Format("select * from p_systemdlltabflowstepgrid where typecode='{0}'", checkNode.GetValue("MenuId"))).Rows.Count != 0)
rightListBoxTab = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemdlltabflowstepgrid where typecode='{0}'", checkNode.GetValue("MenuId")));
string tabName = SqlHelper.ExecuteObject("SQLDT1", string.Format("select SQLDT1 from p_systemdlltab where DllCoid='{0}'", checkNode.GetValue("MenuId"))) + "";
//DataTable NlistBoxTable = SqlHelper.ExecuteDataTable(string.Format("select * from {0}", tabName));
if (!string.IsNullOrEmpty(tabName))
{
gridControlDic.Add(checkNode.Id, gridControlEx);
OrderGridControlDic.Add(checkNode.Id + "", gridControlEx);
rightListData.Columns.Add(tabName);
for (int i = 0; i < rightListBoxTab.Rows.Count; i++)
{
DataRow newRow = rightListData.NewRow();
newRow[tabName] = string.IsNullOrEmpty(rightListBoxTab.Rows[i]["username1"] + "") ? string.Format("{0}({1})", rightListBoxTab.Rows[i]["fieldname"], rightListBoxTab.Rows[i]["fieldname"]) : string.Format("{0}({1})", rightListBoxTab.Rows[i]["username1"], rightListBoxTab.Rows[i]["fieldname"]);
rightListData.Rows.Add(newRow);
}
gridControlEx.gridControl.DataSource = rightListData;
gridControlEx.GridView.Columns[tabName].Caption = checkNode.GetValue("Caption") + "";
gridControlEx.GridView.Columns[tabName].Width = this.rightGridPanel.Width;
gridControlEx.GridView.Columns[tabName].AppearanceHeader.Font = new Font("微软雅黑", 12, FontStyle.Bold);
gridControlEx.GridView.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;//列标题居左
gridControlEx.GridView.Columns[tabName].OptionsColumn.AllowEdit = false;
gridControlEx.Tag = checkNode;
gridControlEx.GridView.BestFitColumns();
gridControlEx.Height = 200;
gridControlEx.Width = this.rightGridPanel.Width - 10;
this.rightGridPanel.Controls.Add(gridControlEx);
gridControlEx.GridView.IndicatorWidth = -1;
GridDragControl dragGrid = new GridDragControl(gridControlEx.GridView, this.CoumnGroup);
dragGrid.OnDragComplete += new GridFragControlCompleteEventHandler(OnDragControlCompleted);
}
}
}
List deleteControl = new List();
int rightGridCount = this.rightGridPanel.Controls.Count;
for (int i = 0; i < rightGridCount; i++)
{
GridControlEx newGridControlEx = this.rightGridPanel.Controls[i] as GridControlEx;
if (!treelist.GetAllCheckedNodes().Contains(newGridControlEx.Tag))
{
deleteControl.Add(newGridControlEx);
}
}
foreach (GridControlEx item in deleteControl)
{
TreeListNode listNode = item.Tag as TreeListNode;
gridControlDic.Remove(Convert.ToInt32(listNode.Id));
OrderGridControlDic.Remove(listNode.Id + "");
this.rightGridPanel.Controls.Remove(item);
}
int top = 5;
for (int i = 0; i < OrderGridControlDic.Count; i++)
{
GridControlEx newGridControlEx = OrderGridControlDic[i] as GridControlEx;
newGridControlEx.Width = newGridControlEx.Parent.Width - 10;
newGridControlEx.Location = new Point(0, top);
top += newGridControlEx.Height + 5;
}
WaitForm.HideForm();
}
#endregion
#region 拖拽完成事件
//
/// 说明:拖拽完成事件
/// 创建人:王一帆
/// 创建日期:2021-09-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The instance containing the event data.
protected void OnDragControlCompleted(object sender, GridDragControlArgs e)
{
if (!groupControlDic.Keys.Contains(Convert.ToInt32(e.SourceGridViewObj.Tag)))
{
GroupBox groupBox = new GroupBox();
groupControlDic.Add(Convert.ToInt32(e.SourceGridViewObj.Tag), groupBox);//Tag为对应树表格id
OrderGroupControlDic.Add(e.SourceGridViewObj.Tag + "", groupBox);
//Dictionary dragItemsInGroupDic = new Dictionary();//groupBox tag
OrderedDictionary dragItemsInGroupDic = new OrderedDictionary();
groupBox.Tag = dragItemsInGroupDic;//记录该控件下所有子控件数据
groupBox.Text = e.SourceGridViewObj.Columns[0].Caption;
groupBox.Font = new Font("微软雅黑", 12, FontStyle.Bold);
groupBox.BackColor = Color.White;
groupBox.Width = this.CoumnGroup.Width - 10;
groupBox.Parent = this.CoumnGroup;
SimpleButton closeBtn = new SimpleButton();
closeBtn.Anchor = AnchorStyles.Right | AnchorStyles.Top;
closeBtn.Text = "×";
closeBtn.Width = 20;
closeBtn.Height = 20;
closeBtn.Click += OnCloseBtn_Click;
closeBtn.Parent = groupBox;
closeBtn.Tag = groupBox;
closeBtn.Top = 5;
closeBtn.Left = closeBtn.Parent.Width - closeBtn.Width - 5;
int top = 5;
for (int i = 0; i < OrderGroupControlDic.Count; i++)
{
GroupBox newGroupBox = OrderGroupControlDic[i] as GroupBox;
newGroupBox.Width = newGroupBox.Parent.Width - 10;
newGroupBox.Location = new Point(0, top);
top += newGroupBox.Height + 5;
}
for (int i = 0; i < e.GridViewSelectRows.Count(); i++)
{
//Dictionary dragItemDic = new Dictionary();
OrderedDictionary dragItemDic = new OrderedDictionary();
SiftColControl.DragItem dragItem = new SiftColControl.DragItem();
dragItemDic.Add(e.GridViewSelectRows[i].Table.Rows.IndexOf(e.GridViewSelectRows[i]) + "", e.GridViewSelectRows[i]);//行索引,行数据
dragItemsInGroupDic.Add(e.GridViewSelectRows[i].Table.Rows.IndexOf(e.GridViewSelectRows[i]) + "", dragItem);
dragItem.ItemLable.Text = e.GridViewSelectRows[i][e.SourceGridViewObj.Columns[0].FieldName] + "";
dragItem.Tag = dragItemDic;
dragItem.ItemLable.Tag = e.SourceGridViewObj;
dragItem.Width = dragItem.ItemLable.Width + 10 + dragItem.ItemBtn.Height;
dragItem.ItemBtn.Width = dragItem.ItemBtn.Height;
dragItem.Parent = groupBox;
dragItem.ItemLable.MouseMove += OnDragItem_MouseMove;
dragItem.ItemLable.MouseLeave += OnDragItem_MouseLeave;
dragItem.ItemLable.MouseClick += OnMouseClick;
Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder btn_ClickEventHanlder = null;
btn_ClickEventHanlder += new Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder(deleteItem);//注册关闭事件
dragItem.setClickEvent(btn_ClickEventHanlder);
Lskj.Control.SiftColControl.DragItem.MouseUpEventHanlder mouseUpEventHanlder = null;
mouseUpEventHanlder += new Lskj.Control.SiftColControl.DragItem.MouseUpEventHanlder(showPopupMenu);//注册右击菜单事件
dragItem.setMouseUpEvent(mouseUpEventHanlder);
}
RedRawDragItem(groupBox);
}
else
{
GroupBox groupBox = groupControlDic[Convert.ToInt32(e.SourceGridViewObj.Tag)];
for (int i = 0; i < e.GridViewSelectRows.Count(); i++)
{
if (!(groupBox.Tag as OrderedDictionary).Contains(e.GridViewSelectRows[i].Table.Rows.IndexOf(e.GridViewSelectRows[i]) + ""))
{
//Dictionary dragItemDic = new Dictionary();
OrderedDictionary dragItemDic = new OrderedDictionary();
SiftColControl.DragItem dragItem = new SiftColControl.DragItem();
dragItemDic.Add(e.GridViewSelectRows[i].Table.Rows.IndexOf(e.GridViewSelectRows[i]) + "", e.GridViewSelectRows[i]);//行索引,行数据
(groupBox.Tag as OrderedDictionary).Add(e.GridViewSelectRows[i].Table.Rows.IndexOf(e.GridViewSelectRows[i]) + "", dragItem);
dragItem.ItemLable.Text = e.GridViewSelectRows[i][e.SourceGridViewObj.Columns[0].FieldName] + "";
dragItem.Tag = dragItemDic;
dragItem.ItemLable.Tag = e.SourceGridViewObj;
dragItem.Width = dragItem.ItemLable.Width + 10 + dragItem.ItemBtn.Height;
dragItem.ItemBtn.Width = dragItem.ItemBtn.Height;
dragItem.Parent = groupBox;
dragItem.ItemLable.MouseMove += OnDragItem_MouseMove;
dragItem.ItemLable.MouseLeave += OnDragItem_MouseLeave;
dragItem.ItemLable.MouseClick += OnMouseClick;
Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder btn_ClickEventHanlder = null;
btn_ClickEventHanlder += new Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder(deleteItem);//注册关闭事件
dragItem.setClickEvent(btn_ClickEventHanlder);
Lskj.Control.SiftColControl.DragItem.MouseUpEventHanlder mouseUpEventHanlder = null;
mouseUpEventHanlder += new Lskj.Control.SiftColControl.DragItem.MouseUpEventHanlder(showPopupMenu);//注册右击菜单事件
dragItem.setMouseUpEvent(mouseUpEventHanlder);
}
}
RedRawDragItem(groupBox);
}
AddColStrToSql();
}
#endregion
#region 删除单个Item控件
///
/// 说明:删除单个Item控件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void deleteItem(Lskj.Control.SiftColControl.DragItem dragItem)
{
GroupBox panel = dragItem.Parent as GroupBox;
OrderedDictionary dragItemsInGroupDic = panel.Tag as OrderedDictionary;
panel.Controls.Remove(dragItem);
string[] keys = new string[(dragItem.Tag as OrderedDictionary).Count];
(dragItem.Tag as OrderedDictionary).Keys.CopyTo(keys, 0);
dragItemsInGroupDic.Remove(keys[0] + "");
if (dragItemsInGroupDic.Count == 0)
{
int index = groupControlDic.Where(n => n.Value == panel).Count() != 0 ? groupControlDic.Where(n => n.Value == panel).First().Key : -1;
if (index > 0)
{
this.CoumnGroup.Controls.Remove(panel);
groupControlDic.Remove(index);//移除没有控件的groupBox
OrderGroupControlDic.Remove(index + "");
int top = 5;
for (int i = 0; i < OrderGroupControlDic.Count; i++)
{
GroupBox newGroupBox = OrderGroupControlDic[i] as GroupBox;
newGroupBox.Width = newGroupBox.Parent.Width - 10;
newGroupBox.Location = new Point(0, top);
top += newGroupBox.Height + 5;
}
}
}
RedRawDragItem(panel);
int Ntop = 5;
for (int i = 0; i < OrderGroupControlDic.Count; i++)
{
GroupBox newGroupBox = OrderGroupControlDic[i] as GroupBox;
newGroupBox.Width = newGroupBox.Parent.Width - 10;
newGroupBox.Location = new Point(0, Ntop);
Ntop += newGroupBox.Height + 5;
}
AddColStrToSql();
}
#endregion
#region 重绘拖拽控件排布
///
/// 说明:重绘拖拽控件排布
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void RedRawDragItem(System.Windows.Forms.Control panelControl)
{
int top = 30; int left = 5;
OrderedDictionary panelControlDic = panelControl.Tag as OrderedDictionary;
//Dictionary.ValueCollection values = (panelControl.Tag as Dictionary).Values;
for (int i = 0; i < panelControlDic.Count; i++)
{
if (left + (panelControlDic[i] as SiftColControl.DragItem).Width > panelControl.Width)
{
top += (panelControlDic[i] as SiftColControl.DragItem).Height + 5; left = 5;
(panelControlDic[i] as SiftColControl.DragItem).Location = new Point(left, top);
left += (panelControlDic[i] as SiftColControl.DragItem).Width + 5;
}
else
{
(panelControlDic[i] as SiftColControl.DragItem).Location = new Point(left, top);
left += (panelControlDic[i] as SiftColControl.DragItem).Width + 5;
}
}
if (panelControl.Controls.Count > 0)
{
panelControl.Height = top + panelControl.Controls[panelControl.Controls.Count - 1].Height + 10;
}
}
#endregion
#region 显示右键菜单
///
/// 说明:显示右键菜单
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void showPopupMenu(Lskj.Control.SiftColControl.DragItem dragItem, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.ClickControl = dragItem;
popupMenu.ShowPopup(System.Windows.Forms.Control.MousePosition);
}
}
#endregion
#region 右键菜单点击事件
///
/// 说明:右键菜单点击事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnItem_ItemClick(object sender, ItemClickEventArgs e)
{
this.IsChangeItemColor = true;
//GridView leftGridView = (this.ClickControl as SiftColControl.DragItem).ItemLable.Tag as GridView;
//this.sqlRichTextBox.Text = string.Format("{0}\r\nfrom {1} {2}", this.sqlRichTextBox.Text.Substring(0, this.sqlRichTextBox.Text.LastIndexOf(',')), leftGridView.Columns[0].FieldName, e.Item.Name + "");
if (this.sqlJoinText.Contains("join"))
this.sqlJoinText = this.sqlJoinText.Substring(0, this.sqlJoinText.LastIndexOf(' ')) + " " + e.Item.Name + "";
else
this.sqlJoinText += " " + e.Item.Name + "";
}
#endregion
#region 选择关联时鼠标滑动、离开和点击事件
///
/// 说明:选择关联时鼠标滑动、离开和点击事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnMouseClick(object sender, MouseEventArgs e)
{
System.Windows.Forms.Control control = (System.Windows.Forms.Control)sender;
if (IsChangeItemColor == true && control.Parent.Parent != this.ClickControl.Parent && e.Button == MouseButtons.Left)
{
SiftColControl.DragItem rightControl = control.Parent as SiftColControl.DragItem;
SiftColControl.DragItem leftControl = this.ClickControl as SiftColControl.DragItem;
string leftColStr = leftControl.ItemLable.Text.Substring(leftControl.ItemLable.Text.IndexOf('(') + 1, leftControl.ItemLable.Text.IndexOf(')') - leftControl.ItemLable.Text.IndexOf('(') - 1);
string rightColStr = rightControl.ItemLable.Text.Substring(rightControl.ItemLable.Text.IndexOf('(') + 1, rightControl.ItemLable.Text.IndexOf(')') - rightControl.ItemLable.Text.IndexOf('(') - 1);
//关联操作
//this.sqlRichTextBox.Text = string.Format("{0} {1} on {2} ={3}", this.sqlRichTextBox.Text, (rightControl.ItemLable.Tag as GridView).Columns[0].FieldName, leftColStr, rightColStr);
if (this.sqlJoinText.Contains((rightControl.ItemLable.Tag as GridView).Columns[0].FieldName))
{
this.sqlRichTextBox.Text = string.Format("{0} {1} on {2} ={3}", this.sqlColText.Substring(0, this.sqlColText.LastIndexOf(',')) + this.sqlJoinText, (leftControl.ItemLable.Tag as GridView).Columns[0].FieldName, leftColStr, rightColStr);
}
else
this.sqlRichTextBox.Text = string.Format("{0} {1} on {2} ={3}", this.sqlColText.Substring(0, this.sqlColText.LastIndexOf(',')) + this.sqlJoinText, (rightControl.ItemLable.Tag as GridView).Columns[0].FieldName, leftColStr, rightColStr);
control.BackColor = Color.Transparent;
this.IsChangeItemColor = false;
}
}
private void OnDragItem_MouseLeave(object sender, EventArgs e)
{
System.Windows.Forms.Control control = (System.Windows.Forms.Control)sender;
if (IsChangeItemColor == true && control.Parent.Parent != this.ClickControl.Parent)
{
control.BackColor = Color.Transparent;
}
}
private void OnDragItem_MouseMove(object sender, MouseEventArgs e)
{
System.Windows.Forms.Control control = (System.Windows.Forms.Control)sender;
if (IsChangeItemColor == true && control.Parent.Parent != this.ClickControl.Parent)
{
control.BackColor = Color.FromArgb(0, 108, 206);
}
}
#endregion
#region grouBox关闭按钮事件
///
/// 说明:grouBox关闭按钮事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnCloseBtn_Click(object sender, EventArgs e)
{
System.Windows.Forms.Control control = ((System.Windows.Forms.Control)sender).Tag as System.Windows.Forms.Control;
control.Parent.Controls.Remove(control);
int index = groupControlDic.Where(n => n.Value == control).Count() != 0 ? groupControlDic.Where(n => n.Value == control).First().Key : -1;
if (index > 0)
{
groupControlDic.Remove(index);//移除没有控件的groupBox
OrderGroupControlDic.Remove(index + "");
int top = 5;
for (int i = 0; i < OrderGroupControlDic.Count; i++)
{
GroupBox newGroupBox = OrderGroupControlDic[i] as GroupBox;
newGroupBox.Width = newGroupBox.Parent.Width - 10;
newGroupBox.Location = new Point(0, top);
top += newGroupBox.Height + 5;
}
}
AddColStrToSql();
}
#endregion
#region 清除按钮点击事件
///
/// 说明:清除按钮点击事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnClearBtn_Click(object sender, EventArgs e)
{
this.CoumnGroup.Controls.Clear();
groupControlDic.Clear();
OrderGroupControlDic.Clear();
this.gcMain.gridControl.DataSource = new DataTable();
this.gcMain.GridView.Columns.Clear();
this.ResGridInfText.Text = "";
this.sqlRichTextBox.Text = "";
}
#endregion
#region 窗体大小改变事件
///
/// 说明:窗体大小改变事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnFrmAutoSqlLoad_SizeChanged(object sender, EventArgs e)
{
int top = 5;
for (int i = 0; i < OrderGridControlDic.Count; i++)
{
GridControlEx newGridControlEx = OrderGridControlDic[i] as GridControlEx;
newGridControlEx.Width = newGridControlEx.Parent.Width - 10;
newGridControlEx.Location = new Point(0, top);
top += newGridControlEx.Height + 5;
}
}
#endregion
#region 分割条位置改变事件
///
/// 说明:分割条位置改变事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnTopSplitContainerControl_SplitterPositionChanged(object sender, EventArgs e)
{
int top = 5;
for (int i = 0; i < OrderGroupControlDic.Count; i++)
{
GroupBox newGroupBox = OrderGroupControlDic[i] as GroupBox;
newGroupBox.Width = newGroupBox.Parent.Width - 10;
newGroupBox.Location = new Point(0, top);
top += newGroupBox.Height + 5;
}
int Ntop = 5;
for (int i = 0; i < OrderGridControlDic.Count; i++)
{
GridControlEx newGridControlEx = OrderGridControlDic[i] as GridControlEx;
newGridControlEx.Width = newGridControlEx.Parent.Width - 10;
newGridControlEx.Location = new Point(0, Ntop);
Ntop += newGridControlEx.Height + 5;
}
}
#endregion
#region 生成按钮点击事件
///
/// 说明:生成按钮点击事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnBtn_Produce_Click(object sender, EventArgs e)
{
try
{
DataTable produceTable = SqlHelper.ExecuteDataTable(this.sqlRichTextBox.Text);
if (produceTable != null)
{
this.gcMain.gridControl.DataSource = produceTable;
this.ResGridInfText.Text = "生成成功!";
this.ResGridInfText.Font = new Font("微软雅黑", 10);
}
else
{
this.ResGridInfText.Text = "生成失败!";
this.ResGridInfText.Font = new Font("微软雅黑", 10);
this.ResGridInfText.ForeColor = Color.Red;
}
}
catch (Exception)
{
this.ResGridInfText.Text = "生成失败,sql语句错误!";
this.ResGridInfText.Font = new Font("微软雅黑", 10);
this.ResGridInfText.ForeColor = Color.Red;
}
}
#endregion
#region 确定按钮点击事件
///
/// 说明:确定按钮,窗口关闭事件
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnBtn_determine_Click(object sender, EventArgs e)
{
EditText = this.sqlRichTextBox.Text;
this.Close();
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
#endregion
#endregion
}
}