1408 lines
61 KiB
C#
1408 lines
61 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using NewMyFormDesigner.Model;
|
|
using System.Collections;
|
|
using Lskj.Core;
|
|
|
|
namespace NewMyFormDesigner
|
|
{
|
|
public partial class MyFormDesigner : Form
|
|
{
|
|
public string FrmKey = "";//369bd9a6-c684-4436-8f10-e48904b296da
|
|
public string SelectSQL { get; set; }
|
|
public string updateSQL { get; set; }
|
|
public string DllCoid { get; set; }
|
|
/// <summary>
|
|
/// 服务器名
|
|
/// </summary>
|
|
public string ServerName { get; set; }
|
|
/// <summary>
|
|
/// 数据库名
|
|
/// </summary>
|
|
public string DatabaseName { get; set; }
|
|
/// <summary>
|
|
/// 账号
|
|
/// </summary>
|
|
public string AccountNumber { get; set; }
|
|
/// <summary>
|
|
/// 密码
|
|
/// </summary>
|
|
public string Password { get; set; }
|
|
//模块类别,1=单表,2=单据
|
|
public int Modtype { get; set; }
|
|
|
|
|
|
public DesignerControl dc { get; set; }
|
|
private DataTable dtFiled = new DataTable();
|
|
private DataTable dtColumns = new DataTable();
|
|
private P_systemControlParent pModel;
|
|
private DataTable dtGroup = new DataTable();//页面信息表
|
|
public bool existenceColorAndPosition = false;//是否右边框颜色和边框标题位置的属性
|
|
public MyFormDesigner()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 初始化工具定义界面
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
|
|
|
|
this.gcFiled.AutoGenerateColumns = false;
|
|
this.gcGroup.AutoGenerateColumns = false;
|
|
this.gridControl1.AutoGenerateColumns = false;
|
|
|
|
string LinkString = string.Empty;
|
|
ConnectionType connectionType = ConnectionType.SqlServer;
|
|
if (!string.IsNullOrWhiteSpace(ServerName) && !string.IsNullOrWhiteSpace(DatabaseName) && !string.IsNullOrWhiteSpace(AccountNumber) && !string.IsNullOrWhiteSpace(Password))
|
|
{
|
|
LinkString = string.Format("Server ={0}; Database ={1}; Persist Security Info = True; User ID ={2}; Password ={3}; Connection Timeout = 5; MultipleActiveResultSets = true", ServerName, DatabaseName, AccountNumber, Password);
|
|
}
|
|
|
|
|
|
DialogResult dr = MessageBox.Show("是否为达梦数据库?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (dr == System.Windows.Forms.DialogResult.Yes)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(ServerName) && !string.IsNullOrWhiteSpace(DatabaseName) && !string.IsNullOrWhiteSpace(AccountNumber))
|
|
{
|
|
string connect = "Nzg5REZBQ0IzMjYzQkQzRTZFRTExNjY5MThCNjUwQTVFRUQyMDMxQzI5REIwODY5REIwMkVCQzQ4MTMzRDhDNEU1N0JFREI0MDM3MTQ1MDZGQzdGOEQxQTE4MkQ2QzgyNEE4RkMzRDQzQUM4MzgyOEQ2REZERTIzQzBDMjJGQUE=";
|
|
string hostname = Environment.MachineName;
|
|
if (!string.IsNullOrWhiteSpace(Password))
|
|
{
|
|
LinkString = string.Format("Server={0}; schema={1}; UserId={2}; PWD={3};host={4}", ServerName, DatabaseName, AccountNumber, Password, hostname);
|
|
}
|
|
else
|
|
{
|
|
LinkString = string.Format(Lskj.Util.AESUtil.Decrypt(connect), ServerName, DatabaseName, AccountNumber, hostname);
|
|
}
|
|
connectionType = ConnectionType.DmServer;
|
|
}
|
|
}
|
|
//MessageBox.Show(LinkString);
|
|
|
|
|
|
if (DBConfig.Instance.CreateConnection(LinkString, connectionType))
|
|
{
|
|
//MessageBox.Show("1");
|
|
InitData();
|
|
DataTable dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemDlltab where formkey='{0}'", FrmKey));
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
this.DllCoid = dt.Rows[0]["DllCoid"] + "";
|
|
this.Modtype = 1;
|
|
}
|
|
else
|
|
{
|
|
dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systembilltype where formkey='{0}'", FrmKey));
|
|
if(dt.Rows.Count>0) this.DllCoid = dt.Rows[0]["typeCode"] + "";
|
|
this.Modtype = 2;
|
|
}
|
|
|
|
}
|
|
//MessageBox.Show("2");
|
|
}
|
|
|
|
|
|
private void InitData()
|
|
{
|
|
dc = dcMain;
|
|
dc._hostFrame.Controls.Clear();
|
|
dc._overlayer.Controls.Clear();
|
|
|
|
|
|
string ExtensionField = "";
|
|
string sqlValue = "select* from v_systemcontrolTab where 1 <> 1";
|
|
DataTable dt = SqlHelper.ExecuteDataSet(sqlValue).Tables[0];
|
|
if (dt.Columns.Contains("columns_id1"))
|
|
{
|
|
ExtensionField += ",a.columns_id1";
|
|
}
|
|
if (dt.Columns.Contains("row_id1"))
|
|
{
|
|
ExtensionField += ",a.row_id1";
|
|
}
|
|
if (dt.Columns.Contains("groupname"))
|
|
{
|
|
ExtensionField += ",a.groupname";
|
|
}
|
|
|
|
//绑定数据库字段
|
|
string sql = @"select a.formKey,isnull(b.orderid,isnull(a.orderid,0)) as orderid,a.fieldid,a.fieldname,
|
|
a.username,a.fieldtypeid,isnull(a.controlLeft,0) as controlLeft,isnull(a.controlTop,0) as controlTop,
|
|
isnull(a.controlHeight,21) as controlHeight,isnull(a.controlWidth,120) as controlWidth,isnull(b.Columns_Id,a.Column_Id) as Column_Id,
|
|
isnull(a.tabOrder,b.tabOrder) as tabOrder,a.defaultValue,
|
|
cast(case when isnull(b.id,0)=0 then 0 else 1 end as bit) as isAdd
|
|
" + ExtensionField + " from v_systemcontrolTab a"
|
|
+ " left join p_systemControlLocation b on a.formKey=b.formKey "
|
|
+ " and lower(a.fieldname)=lower(b.fieldName)"
|
|
+ " where a.formKey='" + FrmKey + "'" +
|
|
" order by a.orderid";
|
|
//MessageBox.Show(sql);
|
|
dtFiled = SqlHelper.ExecuteDataSet(sql).Tables[0];
|
|
|
|
|
|
DataRow dr = dtFiled.NewRow();
|
|
dr["fieldname"] = "分组框";
|
|
dr["fieldtypeid"] = "8888";
|
|
dr["orderid"] = 0;
|
|
dr["column_id"] = 0;
|
|
dtFiled.Rows.InsertAt(dr, 0);
|
|
|
|
DataRow drPage = dtFiled.NewRow();
|
|
drPage["fieldname"] = "分页组件";
|
|
drPage["fieldtypeid"] = "8889";
|
|
drPage["orderid"] = 0;
|
|
drPage["column_id"] = 0;
|
|
dtFiled.Rows.InsertAt(drPage, 0);
|
|
|
|
DataRow drDivider = dtFiled.NewRow();
|
|
drDivider["fieldname"] = "横向分割线";
|
|
drDivider["fieldtypeid"] = "8890";
|
|
drDivider["orderid"] = 0;
|
|
drDivider["column_id"] = 0;
|
|
dtFiled.Rows.InsertAt(drDivider, 0);
|
|
|
|
gcFiled.DataSource = dtFiled;
|
|
|
|
dtGroup = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemAddGroup where formKey='{0}'", FrmKey));
|
|
gcGroup.DataSource = dtGroup;
|
|
|
|
sql = "select FormKey,Column_Id,controlLeft,controlTop,controlWidth,controlHeight,RowSpace from p_systemcontrolColumn where formkey='" + FrmKey + "'";
|
|
dtColumns = SqlHelper.ExecuteDataSet(sql).Tables[0];
|
|
if (dtColumns.Rows.Count < 1)
|
|
{
|
|
DataRow dr1 = dtColumns.NewRow();
|
|
dr1["formkey"] = FrmKey;
|
|
dr1["column_id"] = 1;
|
|
dr1["controlleft"] = 5;
|
|
dr1["controlTop"] = 5;
|
|
dr1["controlWidth"] = 120;
|
|
dr1["controlHeight"] = 21;
|
|
dr1["rowspace"] = 5;
|
|
dtColumns.Rows.InsertAt(dr1, 0);
|
|
}
|
|
gridControl1.DataSource = dtColumns;
|
|
|
|
LoadDefault();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定已经设置过参数
|
|
/// </summary>
|
|
private void LoadDefault()
|
|
{
|
|
|
|
DataTable dtLoction = SqlHelper.ExecuteDataSet(string.Format("select * from p_systemControlLocation where formkey='{0}'", FrmKey)).Tables[0];
|
|
if (dtLoction.Rows.Count==0)
|
|
{
|
|
//查询结果没有值就去掉大括号 2023-10-20
|
|
FrmKey = FrmKey.Replace("{", "").Replace("}", "");
|
|
updateSQL = updateSQL.Replace("{", "").Replace("}", "");
|
|
dtLoction = SqlHelper.ExecuteDataSet(string.Format("select * from p_systemControlLocation where formkey='{0}'", FrmKey)).Tables[0];
|
|
|
|
}
|
|
DataTable dtControlPL = SqlHelper.ExecuteDataTable(string.Format("select * from P_systemControlParent where formkey='{0}'", FrmKey));
|
|
DataRow CotrolPlRow = dtControlPL.Rows.Count > 0 ? dtControlPL.Rows[0] : null;
|
|
pModel = new P_systemControlParent(CotrolPlRow);
|
|
dc = dcMain;
|
|
if (pModel != null)
|
|
{
|
|
plRight.Controls.Clear();
|
|
dc = new DesignerControl(pModel.parentWidth, pModel.parentHeight);
|
|
dc.Height = pModel.parentHeight;
|
|
dc.Width = pModel.parentWidth;
|
|
dc.AutoScroll = true;
|
|
dc.Dock = DockStyle.Fill;
|
|
|
|
plRight.Controls.Add(dc);
|
|
|
|
plRight.AutoScroll = true;
|
|
dc.BringToFront();
|
|
}
|
|
|
|
foreach (DataRow row in dtLoction.Rows)
|
|
{
|
|
string fieldid = row["fieldid"].ToString();
|
|
string username = row["username"].ToString();
|
|
string fieldtypeid = row["fieldtypeid"].ToString();
|
|
string fieldname = row["fieldname"].ToString();
|
|
string defaultValue = row["defaultValue"].ToString();
|
|
string column_id = row["columns_id"].ToString();
|
|
int orderid = Convert.ToInt32(row["orderid"]);
|
|
Control ctr = ControlHelper.CreateControl(username, fieldname, Convert.ToInt32(fieldtypeid));
|
|
|
|
int posX = Convert.ToInt32(row["controlLeft"]);
|
|
int posY = Convert.ToInt32(row["controlTop"]);
|
|
int width = Convert.ToInt32(row["controlWidth"]);
|
|
int height = Convert.ToInt32(row["controlHeight"]);
|
|
int tabOrder = Convert.ToInt32(row["tabOrder"]);
|
|
string id = row["id"].ToString();
|
|
|
|
if (ctr == null)
|
|
continue;
|
|
ctr.Location = (new Point(posX, posY));//屏幕坐标转换成控件容器坐标
|
|
ctr.Width = width;
|
|
ctr.Height = height;
|
|
ctr.TabIndex = tabOrder>=0? tabOrder:0;
|
|
|
|
ctr.Tag = new object[] { fieldid, username, fieldtypeid, fieldname, defaultValue, column_id, orderid, id };
|
|
ctr.Parent = dc._hostFrame;
|
|
ctr.BringToFront();
|
|
}
|
|
|
|
string addgroup_sql = String.Format("select * from p_systemaddgroup where formkey='{0}'", FrmKey);
|
|
DataTable dtGroup = SqlHelper.ExecuteDataSet(addgroup_sql).Tables[0];
|
|
existenceColorAndPosition = dtGroup.Columns.Contains("borderColor") && dtGroup.Columns.Contains("titlePosition");
|
|
|
|
foreach (DataRow row in dtGroup.Rows)
|
|
{
|
|
if (Convert.ToInt32(row["controlType"]) == 333)
|
|
{
|
|
LabelGroupBox gb = new LabelGroupBox();
|
|
gb.Text = row["groupName"] + "";
|
|
gb.Width = Convert.ToInt32(row["controlWidth"]);
|
|
gb.Left = Convert.ToInt32(row["controlLeft"]);
|
|
gb.Top = Convert.ToInt32(row["controlTop"]);
|
|
gb.Height = Convert.ToInt32(row["controlHeight"]);
|
|
if (existenceColorAndPosition)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(row["titlePosition"] + "")) gb.TitlePosition = Convert.ToInt32(row["titlePosition"]);
|
|
if (!string.IsNullOrWhiteSpace(row["borderColor"] + "")) gb.BorderColor = ColorTranslator.FromHtml(row["borderColor"] + "");
|
|
}
|
|
string id = row["id"].ToString();
|
|
gb.Tag = new string[] { "", row["groupName"] + "", "8888", "", "", "", "", id };
|
|
gb.SendToBack();
|
|
dc._hostFrame.Controls.Add(gb);
|
|
}
|
|
if (Convert.ToInt32(row["controlType"]) == 332)
|
|
{
|
|
Panel pnlPage = new Panel();
|
|
pnlPage.Text = row["groupName"] + "";
|
|
pnlPage.Width = Convert.ToInt32(row["controlWidth"]);
|
|
pnlPage.Left = Convert.ToInt32(row["controlLeft"]);
|
|
pnlPage.Top = Convert.ToInt32(row["controlTop"]);
|
|
pnlPage.Height = Convert.ToInt32(row["controlHeight"]);
|
|
string id = row["id"].ToString();
|
|
pnlPage.Tag = new string[] { "", row["groupName"] + "", "8889", "", "", "", "", id };
|
|
pnlPage.BackColor = Color.LightGreen;
|
|
pnlPage.SendToBack();
|
|
dc._hostFrame.Controls.Add(pnlPage);
|
|
}
|
|
if (Convert.ToInt32(row["controlType"]) == 334)
|
|
{
|
|
LabelDivider newlabel = new LabelDivider();
|
|
//newlabel.AutoSize = false;
|
|
//newlabel.BorderStyle = BorderStyle.Fixed3D;
|
|
newlabel.Top = int.Parse(row["controlTop"] + "");
|
|
newlabel.Left = int.Parse(row["controlLeft"] + "");
|
|
newlabel.Height = int.Parse(row["controlHeight"] + "");
|
|
newlabel.Width = int.Parse(row["controlWidth"] + "");
|
|
string id = row["id"].ToString();
|
|
newlabel.Tag = new string[] { "", row["groupName"] + "", "8890", "", "", "", "", id };
|
|
newlabel.SendToBack();
|
|
dc._hostFrame.Controls.Add(newlabel);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void gvFiled_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button != MouseButtons.Left)
|
|
return;
|
|
if(gcFiled.CurrentCell==null) return;
|
|
int RowIndex = gcFiled.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataTable dt = gcFiled.DataSource == null ? new DataTable() : gcFiled.DataSource as DataTable;//克隆DataTable结构
|
|
DataRow row = dt.Rows[RowIndex];
|
|
if (row != null)
|
|
{
|
|
string fieldid = row["fieldid"].ToString();
|
|
string username = row["username"].ToString();
|
|
string fieldtypeid = row["fieldtypeid"].ToString();
|
|
string fieldname = row["fieldname"].ToString();
|
|
string defaultValue = row["defaultValue"].ToString();
|
|
int column_Id = Convert.ToInt32(row["column_id"]);
|
|
int orderId = Convert.ToInt32(row["orderid"]);
|
|
Control[] ctr = dc.Controls.Find(fieldname, true);
|
|
if (ctr.Length > 0 && !(ctr[0] is LabelGroupBox))
|
|
{
|
|
//XtraMessageBox.Show("抱歉,控件已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
//(ctr[0] as Control).Focus();
|
|
return;
|
|
}
|
|
object[] strs = { fieldid, username, fieldtypeid, fieldname, defaultValue, column_Id, orderId };
|
|
DoDragDrop(strs, DragDropEffects.Copy);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除全部控件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void barDeleteAll_ItemClick(object sender, EventArgs e)
|
|
{
|
|
DialogResult dr = MessageBox.Show("确定全部删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (dr == System.Windows.Forms.DialogResult.Yes)
|
|
{
|
|
dc._hostFrame.Controls.Clear();
|
|
dc._overlayer.Controls.Clear();
|
|
StringBuilder sqlbuild = new StringBuilder();
|
|
sqlbuild.Append(string.Format(" delete p_systemControlLocation where formkey='{0}';delete p_systemAddGroup where formkey='{0}';", FrmKey));
|
|
sqlbuild.Append(updateSQL);
|
|
SqlHelper.ExecuteNonQuery(sqlbuild.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 运行测试窗体
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void barRun_ItemClick(object sender, EventArgs e)
|
|
{
|
|
RunForm runForm = new RunForm();
|
|
runForm.FrmKey = FrmKey;
|
|
runForm.DllCoid = DllCoid;
|
|
runForm.Modtype = Modtype;
|
|
//runForm.db = db;
|
|
runForm.SQL = SelectSQL;
|
|
runForm.ShowDialog();
|
|
}
|
|
/// <summary>
|
|
/// 保存表单
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void barSave_ItemClick(object sender, EventArgs e)
|
|
{
|
|
StringBuilder sqlbuild = new StringBuilder();
|
|
string sql = "";
|
|
try
|
|
{
|
|
|
|
DataTable formTheKey = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemControlParent where formkey='{0}'", FrmKey));
|
|
if (formTheKey != null && formTheKey.Rows.Count > 0) //数据库中是否有这个模块
|
|
{
|
|
sql = " UPDATE p_systemControlParent set parentheight='" + dc._hostFrame.Height.ToString() + "',parentwidth='" + dc._hostFrame.Width.ToString() + "'where formkey='" + FrmKey + "';";
|
|
}
|
|
else
|
|
{
|
|
sql = " insert into p_systemControlParent (formkey,parentheight,parentwidth) values ('" + FrmKey + "'," + dc._hostFrame.Height.ToString() + "," + dc._hostFrame.Width.ToString() + ");";
|
|
|
|
}
|
|
sqlbuild.Append(sql);
|
|
pModel.formKey = FrmKey;
|
|
pModel.parentHeight = dc._hostFrame.Height;
|
|
pModel.parentWidth = dc._hostFrame.Width;
|
|
|
|
DataTable dtColumn = gridControl1.DataSource as DataTable;
|
|
dtColumn.AcceptChanges();
|
|
if ((dtColumn != null) && (dtColumn.Rows.Count > 0))
|
|
{
|
|
sql = " delete p_systemcontrolColumn where formkey='" + FrmKey + "';";
|
|
sqlbuild.Append(sql);
|
|
foreach (DataRow row in dtColumn.Rows)
|
|
{
|
|
sql = String.Format(@" insert into p_systemcontrolColumn (FormKey,Column_Id,controlLeft,controlTop,controlWidth,controlHeight,RowSpace)
|
|
values ('{0}'
|
|
,'{1}'
|
|
,'{2}'
|
|
,'{3}'
|
|
,'{4}'
|
|
,'{5}'
|
|
,'{6}');", FrmKey, row["column_id"], row["controlLeft"], row["controlTop"], row["controlWidth"], row["controlHeight"], row["rowspace"]);
|
|
sqlbuild.Append(sql);
|
|
}
|
|
}
|
|
|
|
if (dtFiled != null && dtFiled.Rows.Count > 0)
|
|
{
|
|
foreach (Control c in dc._hostFrame.Controls)
|
|
{
|
|
//if (c is GroupBox || c is Panel)
|
|
//{
|
|
// string typeid = null; //controlType
|
|
// object[] col = c.Tag as object[];
|
|
// string cid = null; //编号
|
|
// DataTable dt = new DataTable();//数据库中是否存在
|
|
// string name = null; //页面名字
|
|
// string order = null; //页面顺序
|
|
// if (col.Length >= 8)
|
|
// {
|
|
// if (col[7].ToString() != null) cid = col[7].ToString();//当前控件的id
|
|
// if (IsNumberic(cid))
|
|
// {
|
|
// dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemAddGroup where id='{0}'", cid));
|
|
// }
|
|
// }
|
|
// if (c is GroupBox) typeid = "333";
|
|
// if (c is Panel) typeid = "332";
|
|
// if (col.Length >= 9)
|
|
// {
|
|
// ControlProperty controlProperty = col[col.Length - 1] as ControlProperty;
|
|
// }
|
|
|
|
|
|
// if (dt != null && dt.Rows.Count > 0)
|
|
// {
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//根据控件类型拿到tag中的id,出现id根据数据库中是否存在写入新增或修改语句
|
|
if (c is LabelGroupBox)
|
|
{
|
|
LabelGroupBox lgb=c as LabelGroupBox;
|
|
string TitlePosition = lgb.TitlePosition+"";//标题位置
|
|
string colorHtml = ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(lgb.BorderColor.R, lgb.BorderColor.G, lgb.BorderColor.B));//颜色
|
|
|
|
object[] col = c.Tag as object[];
|
|
string cid = null;
|
|
DataTable dt = new DataTable();
|
|
if (col.Length >= 8 && !string.IsNullOrWhiteSpace(col[7] + ""))
|
|
{
|
|
cid = col[7].ToString();//当前控件的id
|
|
if (IsNumberic(cid))
|
|
{
|
|
dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemAddGroup where id='{0}';", cid));
|
|
}
|
|
}
|
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
sql = existenceColorAndPosition ? String.Format(@" UPDATE p_systemAddGroup set
|
|
[GroupName]='{0}'
|
|
,[controlLeft]='{1}'
|
|
,[controlTop]='{2}'
|
|
,[controlHeight]='{3}'
|
|
,[controlWidth]='{4}'
|
|
,[formKey]='{5}'
|
|
,[controlType]='{6}',[borderColor]='{8}',[titlePosition]='{9}' where id='{7}';
|
|
", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 333, cid, colorHtml, TitlePosition) :
|
|
String.Format(@"UPDATE p_systemAddGroup set
|
|
[GroupName]='{0}'
|
|
,[controlLeft]='{1}'
|
|
,[controlTop]='{2}'
|
|
,[controlHeight]='{3}'
|
|
,[controlWidth]='{4}'
|
|
,[formKey]='{5}'
|
|
,[controlType]='{6}' where id='{7}';
|
|
", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 333, cid);
|
|
}
|
|
else
|
|
{
|
|
sql = existenceColorAndPosition ? String.Format(@" INSERT INTO [p_systemAddGroup]
|
|
([GroupName]
|
|
,[controlLeft]
|
|
,[controlTop]
|
|
,[controlHeight]
|
|
,[controlWidth]
|
|
,[formKey]
|
|
,[controlType],[borderColor],[titlePosition])
|
|
VALUES
|
|
('{0}'
|
|
,'{1}'
|
|
,'{2}'
|
|
,'{3}'
|
|
,'{4}'
|
|
,'{5}'
|
|
,'{6}','{7}','{8}');", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 333, colorHtml, TitlePosition) :
|
|
String.Format(@"INSERT INTO [p_systemAddGroup]
|
|
([GroupName]
|
|
,[controlLeft]
|
|
,[controlTop]
|
|
,[controlHeight]
|
|
,[controlWidth]
|
|
,[formKey]
|
|
,[controlType])
|
|
VALUES
|
|
('{0}'
|
|
,'{1}'
|
|
,'{2}'
|
|
,'{3}'
|
|
,'{4}'
|
|
,'{5}'
|
|
,'{6}');", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 333);
|
|
}
|
|
sqlbuild.Append(sql);
|
|
}
|
|
|
|
if (c is Panel)
|
|
{
|
|
object[] col = c.Tag as object[];
|
|
string cid = null;
|
|
DataTable dt = new DataTable();
|
|
if (col.Length >= 8 && !string.IsNullOrWhiteSpace(col[7] + ""))
|
|
{
|
|
cid = col[7].ToString();//当前控件的id
|
|
if (IsNumberic(cid))
|
|
{
|
|
dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemAddGroup where id='{0}';", cid));
|
|
}
|
|
}
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
sql = String.Format(@" UPDATE p_systemAddGroup set
|
|
[GroupName]='{0}'
|
|
,[controlLeft]='{1}'
|
|
,[controlTop]='{2}'
|
|
,[controlHeight]='{3}'
|
|
,[controlWidth]='{4}'
|
|
,[formKey]='{5}'
|
|
,[controlType]='{6}' where id='{7}';
|
|
", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 332, cid);
|
|
}
|
|
else
|
|
{
|
|
sql = String.Format(@" INSERT INTO [p_systemAddGroup]
|
|
([GroupName]
|
|
,[controlLeft]
|
|
,[controlTop]
|
|
,[controlHeight]
|
|
,[controlWidth]
|
|
,[formKey]
|
|
,[controlType])
|
|
VALUES
|
|
('{0}'
|
|
,'{1}'
|
|
,'{2}'
|
|
,'{3}'
|
|
,'{4}'
|
|
,'{5}'
|
|
,'{6}');", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 332);
|
|
}
|
|
sqlbuild.Append(sql);
|
|
}
|
|
|
|
if (c is LabelDivider)
|
|
{
|
|
object[] col = c.Tag as object[];
|
|
string cid = null;
|
|
DataTable dt = new DataTable();
|
|
if (col.Length >= 8 && !string.IsNullOrWhiteSpace(col[7] + ""))
|
|
{
|
|
cid = col[7].ToString();//当前控件的id
|
|
if (IsNumberic(cid))
|
|
{
|
|
dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemAddGroup where id='{0}';", cid));
|
|
}
|
|
}
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
sql = String.Format(@" UPDATE p_systemAddGroup set
|
|
[GroupName]='{0}'
|
|
,[controlLeft]='{1}'
|
|
,[controlTop]='{2}'
|
|
,[controlHeight]='{3}'
|
|
,[controlWidth]='{4}'
|
|
,[formKey]='{5}'
|
|
,[controlType]='{6}' where id='{7}';
|
|
", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 334, cid);
|
|
}
|
|
else
|
|
{
|
|
sql = String.Format(@" INSERT INTO [p_systemAddGroup]
|
|
([GroupName]
|
|
,[controlLeft]
|
|
,[controlTop]
|
|
,[controlHeight]
|
|
,[controlWidth]
|
|
,[formKey]
|
|
,[controlType])
|
|
VALUES
|
|
('{0}'
|
|
,'{1}'
|
|
,'{2}'
|
|
,'{3}'
|
|
,'{4}'
|
|
,'{5}'
|
|
,'{6}');", c.Text, c.Left, c.Top, c.Height, c.Width, FrmKey, 334);
|
|
}
|
|
sqlbuild.Append(sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
sqlbuild.Append(string.Format(" delete p_systemControlLocation where formkey='{0}';", FrmKey));
|
|
foreach (DataRow row in dtFiled.Rows)
|
|
{
|
|
//MessageBox.Show(row["fieldName"].ToString());
|
|
if (row["fieldName"].ToString().Trim() != "")
|
|
{
|
|
//string aaaa= row["fieldName"].ToString().Trim();
|
|
Control[] ctrs = dc.Controls.Find(row["fieldName"].ToString(), true);
|
|
if (ctrs.Length == 0)
|
|
continue;
|
|
Control ctr = ctrs[0];
|
|
bool isGroup = ctr is LabelGroupBox;
|
|
if (!isGroup)
|
|
{
|
|
object[] tags = (object[])ctr.Tag;
|
|
P_systemControlLocation model = new P_systemControlLocation();
|
|
if (tags.Length >= 9)
|
|
{
|
|
ControlProperty controlProperty = tags[tags.Length - 1] as ControlProperty;
|
|
String group_sql = string.Format("select * from p_systemAddGroup where formkey='{0}' and groupName='{1}';", FrmKey, controlProperty.GroupName);
|
|
DataTable dtsql = SqlHelper.ExecuteDataSet(group_sql).Tables[0];
|
|
if (dtsql != null && dtsql.Rows.Count > 0)
|
|
{
|
|
model.GroupId = Convert.ToInt32(dtsql.Rows[0]["id"]);
|
|
}
|
|
else
|
|
{
|
|
model.GroupId = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
model.GroupId = 0;
|
|
}
|
|
model.formKey = FrmKey;
|
|
model.fieldId = Convert.ToInt32(tags[0]);
|
|
model.userName = tags[1].ToString();
|
|
model.fieldTypeId = Convert.ToInt32(tags[2]);
|
|
model.fieldName = tags[3].ToString();
|
|
model.defaultValue = tags[4].ToString();
|
|
|
|
model.controlHeight = ctr.Height;
|
|
model.controlLeft = ctr.Left;
|
|
model.controlTop = ctr.Top;
|
|
model.controlWidth = ctr.Width;
|
|
|
|
model.tabOrder = ctr.TabIndex;
|
|
|
|
sql = @" insert into p_systemcontrollocation (formKey
|
|
,fieldId
|
|
,fieldName
|
|
,userName
|
|
,fieldTypeId
|
|
,defaultValue
|
|
,controlLeft
|
|
,controlTop
|
|
,controlWidth
|
|
,controlHeight
|
|
,GroupId
|
|
,tabOrder
|
|
,Columns_Id
|
|
,orderid) values ('" + FrmKey + "'," +
|
|
tags[0].ToString() + ",'" +
|
|
tags[3].ToString() + "','" +
|
|
tags[1].ToString() + "'," +
|
|
tags[2].ToString() + ",'" +
|
|
tags[4].ToString().Replace("'", "''") + "'," +
|
|
ctr.Left.ToString() + "," +
|
|
ctr.Top.ToString() + "," +
|
|
ctr.Width.ToString() + "," +
|
|
ctr.Height.ToString() + "," +
|
|
model.GroupId.ToString() + "," +
|
|
ctr.TabIndex.ToString() + "," +
|
|
tags[5].ToString() + "," +
|
|
tags[6].ToString() + ");";
|
|
sqlbuild.Append(sql);
|
|
//ldao.Add(model);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(row["username"].ToString());
|
|
}
|
|
|
|
//sqlbuild.Append(updateSQL);
|
|
}
|
|
sqlbuild.Append(updateSQL);
|
|
SqlHelper.ExecuteNonQuery(sqlbuild.ToString());
|
|
MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
System.Windows.Forms.Clipboard.SetText(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
//SqlHelper.ExecuteNonQuery(updateSQL);
|
|
dc._hostFrame.Controls.Clear();
|
|
dc._overlayer.Controls.Clear();
|
|
InitData();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//判断字符串是否为数字
|
|
private bool IsNumberic(string oText)
|
|
{
|
|
try
|
|
{
|
|
int var1 = Convert.ToInt32(oText);
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMeTop(object obj)
|
|
{
|
|
//原理:先添加的控件会在最上面,即可见次序是由index决定的.
|
|
int index = this.Controls.GetChildIndex((Control)obj);//取得要置顶控件的index
|
|
ArrayList AL = new ArrayList();//用来装入控件的容器
|
|
for (int i = 0; i < index; i++)//把要置顶控件上面的控件都装入容器
|
|
{
|
|
AL.Add(this.Controls[i]);
|
|
}
|
|
for (int i = 0; i < AL.Count; i++)
|
|
{
|
|
//用一次删除和一次添加操作,让它上面的控件排到下面去.
|
|
this.Controls.Remove((Control)AL[i]);
|
|
this.Controls.Add((Control)AL[i]);
|
|
}
|
|
}
|
|
|
|
private void barDelete_ItemClick(object sender, EventArgs e)
|
|
{
|
|
if (dc._overlayer._currentCtrl == null)
|
|
{
|
|
return;
|
|
}
|
|
string id = null;
|
|
object[] obj = dc._overlayer._currentCtrl.Tag as object[];
|
|
string sql = "";
|
|
if (obj.Length >= 8)
|
|
{
|
|
if (IsNumberic(id)&& obj[7] != null)
|
|
{
|
|
id = obj[7].ToString();//当前控件的id
|
|
StringBuilder sqlbuild = new StringBuilder();
|
|
if (dc._overlayer._currentCtrl is LabelGroupBox || dc._overlayer._currentCtrl is Panel || dc._overlayer._currentCtrl is LabelDivider)
|
|
{
|
|
sql = "delete from p_systemAddGroup where id='" + id + "';";
|
|
}
|
|
else
|
|
{
|
|
sql = "delete from p_systemcontrollocation where id='" + id + "';";
|
|
}
|
|
sqlbuild.Append(sql);
|
|
sqlbuild.Append(updateSQL);
|
|
SqlHelper.ExecuteNonQuery(sqlbuild.ToString());
|
|
}
|
|
}
|
|
dc._hostFrame.Controls.Remove(dc._overlayer._currentCtrl);
|
|
dc._overlayer.Controls.Clear();
|
|
}
|
|
|
|
private void barClose_ItemClick(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
private void ToolStripMenuItem4_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
int RowIndex = gcFiled.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataRow dr = dt.Rows[RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() == "")
|
|
return;
|
|
int icol = Convert.ToInt32(dr["column_id"]);
|
|
gcFiled.ClearSelection();
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
DataRow row = dt.Rows[i];
|
|
if (row["formkey"].ToString() == "")
|
|
continue;
|
|
if (row["column_id"].ToString() == icol.ToString())
|
|
this.gcFiled.Rows[i].Selected = true;
|
|
}
|
|
}
|
|
|
|
private void ToolStripMenuItemJql_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
int RowIndex = gcFiled.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataRow dr = dt.Rows[RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() == "")
|
|
return;
|
|
int icol = Convert.ToInt32(dr["controlleft"]);
|
|
gcFiled.ClearSelection();
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
DataRow row = dt.Rows[i];
|
|
if (row["formkey"].ToString() == "")
|
|
continue;
|
|
if (row["controlleft"].ToString() == icol.ToString())
|
|
this.gcFiled.Rows[i].Selected = true;
|
|
}
|
|
}
|
|
|
|
private void ToolStripMenuItemCyl_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
int RowIndex = gcFiled.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataRow dr = dt.Rows[RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() == "")
|
|
return;
|
|
int icol = Convert.ToInt32(dr["controlleft"]);
|
|
gcFiled.ClearSelection();
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
DataRow row = dt.Rows[i];
|
|
if (row["formkey"].ToString() == "")
|
|
continue;
|
|
if ((Convert.ToInt32(row["controlleft"]) >= icol - 10) && (Convert.ToInt32(row["controlleft"]) <= icol + 10))
|
|
this.gcFiled.Rows[i].Selected = true;
|
|
}
|
|
}
|
|
|
|
private void ToolStripMenuItemJqh_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
int RowIndex = gcFiled.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataRow dr = dt.Rows[RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() == "")
|
|
return;
|
|
int icol = Convert.ToInt32(dr["controlTop"]);
|
|
gcFiled.ClearSelection();
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
DataRow row = dt.Rows[i];
|
|
if (row["formkey"].ToString() == "")
|
|
continue;
|
|
if (row["controlTop"].ToString() == icol.ToString())
|
|
this.gcFiled.Rows[i].Selected = true;
|
|
}
|
|
}
|
|
|
|
private void ToolStripMenuItemCyh_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
int RowIndex = gcFiled.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataRow dr = dt.Rows[RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() == "")
|
|
return;
|
|
int icol = Convert.ToInt32(dr["controlTop"]);
|
|
gcFiled.ClearSelection();
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
DataRow row = dt.Rows[i];
|
|
if (row["formkey"].ToString() == "")
|
|
continue;
|
|
if ((Convert.ToInt32(row["controlTop"]) >= icol - 10) && (Convert.ToInt32(row["controlTop"]) <= icol + 10))
|
|
this.gcFiled.Rows[i].Selected = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重绘表格颜色方法
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void gcFiled_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
|
|
{
|
|
DataTable dt = gcFiled.DataSource == null ? new DataTable() : gcFiled.DataSource as DataTable;//克隆DataTable结构
|
|
if (e.RowIndex < 0 || e.RowIndex > dt.Rows.Count - 1) return;
|
|
DataRow dr = dt.Rows[e.RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formKey"] + "" == "")
|
|
return;
|
|
if (dr["isAdd"].ToString() == "0")
|
|
gcFiled.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
|
|
if ((Convert.ToInt32(dr["controlLeft"]) < 0) || (Convert.ToInt32(dr["controlTop"]) < 0) ||
|
|
(Convert.ToInt32(dr["controlLeft"]) > dc._hostFrame.Width) ||
|
|
(Convert.ToInt32(dr["controlTop"]) > dc._hostFrame.Height) ||
|
|
(Convert.ToInt32(dr["controlLeft"]) + Convert.ToInt32(dr["controlWidth"]) > dc._hostFrame.Width) ||
|
|
(Convert.ToInt32(dr["controlTop"]) + Convert.ToInt32(dr["controlHeight"]) > dc._hostFrame.Height))
|
|
{
|
|
gcFiled.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Blue;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 表格点击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void gvFiled_RowCellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
int RowIndex = gcFiled.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataTable dt = gcFiled.DataSource == null ? new DataTable() : gcFiled.DataSource as DataTable;//克隆DataTable结构
|
|
DataRow dr = dt.Rows[RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
string ctlName = dr["fieldName"].ToString();
|
|
Control[] ctr = this.Controls.Find(ctlName, true);
|
|
if ((ctr == null) || (ctr.Length < 1))
|
|
return;
|
|
dc._overlayer._currentCtrl = ctr[0];
|
|
//MessageBox.Show(ctr[0].Bounds.X.ToString() + "Y:" + ctr[0].Bounds.Y.ToString());
|
|
MouseEventArgs ex = new MouseEventArgs(MouseButtons.Left, 0, ctr[0].Bounds.X + 20, ctr[0].Bounds.Y + 50, 0);
|
|
dc._overlayer.UserMouseDown(ex);
|
|
dc._overlayer.UserMouseUp(ex);
|
|
}
|
|
|
|
|
|
|
|
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (!char.IsDigit(e.KeyChar))
|
|
e.Handled = false;
|
|
}
|
|
|
|
private void simpleButton4_Click(object sender, EventArgs e)
|
|
{
|
|
List<DataRow> selRow = new List<DataRow>();
|
|
DataTable dt = gcFiled.DataSource == null ? new DataTable() : gcFiled.DataSource as DataTable;//克隆DataTable结构
|
|
foreach (DataGridViewRow row in gcFiled.SelectedRows)
|
|
{
|
|
DataRow dr = (row.DataBoundItem as DataRowView).Row;//微软提供的唯一的转换DataRow
|
|
selRow.Add(dr);
|
|
}
|
|
if ((selRow == null) || (selRow.Count < 1))
|
|
{
|
|
MessageBox.Show("未选中需要调整的字段");
|
|
return;
|
|
}
|
|
|
|
if (comboBox1.Text == "" )
|
|
{
|
|
MessageBox.Show("请选择调整类型");
|
|
return;
|
|
}
|
|
if (comboBox2.Text == "")
|
|
{
|
|
MessageBox.Show("请选择调整属性");
|
|
return;
|
|
}
|
|
|
|
if (numericUpDown1.Value == 0)
|
|
{
|
|
MessageBox.Show("请输入调整值");
|
|
return;
|
|
}
|
|
|
|
DialogResult dlrg = MessageBox.Show("是否对选中的字段进行批量调整?", "询问", MessageBoxButtons.YesNo);
|
|
if (dlrg != DialogResult.Yes)
|
|
return;
|
|
string tzField = "";
|
|
switch (comboBox2.SelectedIndex)
|
|
{
|
|
case 0: tzField = "controlLeft"; break;
|
|
case 1: tzField = "controlTop"; break;
|
|
case 2: tzField = "controlWidth"; break;
|
|
case 3: tzField = "controlHeight"; break;
|
|
case 4: tzField = "column_id"; break;
|
|
}
|
|
foreach (DataRow dr in selRow)
|
|
{
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() != "")
|
|
{
|
|
int value = Convert.ToInt32(numericUpDown1.Value);
|
|
if (comboBox1.SelectedIndex == 1)
|
|
{
|
|
value = Convert.ToInt32(dr[tzField]) + value;
|
|
}
|
|
dr[tzField] = value;
|
|
|
|
string ctlName = dr["fieldname"].ToString();
|
|
Control[] ctr = this.Controls.Find(ctlName, true);
|
|
if ((ctr == null) || (ctr.Length < 1))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
switch (comboBox2.SelectedIndex)
|
|
{
|
|
case 0: ctr[0].Left = value; break;
|
|
case 1: ctr[0].Top = value; break;
|
|
case 2: ctr[0].Width = value; break;
|
|
case 3: ctr[0].Height = value; break;
|
|
case 4:
|
|
{
|
|
object[] objs = (object[])ctr[0].Tag;
|
|
objs[5] = Convert.ToInt32(numericUpDown1.Value);
|
|
ctr[0].Tag = objs;
|
|
break;
|
|
};
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void barButtonItem9_ItemClick(object sender, EventArgs e)
|
|
{
|
|
DialogResult dr = MessageBox.Show("确定将数据恢复到上次保存状态?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (dr == System.Windows.Forms.DialogResult.Yes)
|
|
{
|
|
InitData();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = gridControl1.DataSource as DataTable;
|
|
if (dt == null)
|
|
return;
|
|
DataRow dr1 = dtColumns.NewRow();
|
|
dr1["formkey"] = FrmKey;
|
|
dr1["column_id"] = gridControl1.RowCount + 1;
|
|
dr1["controlleft"] = 5;
|
|
dr1["controlTop"] = 5;
|
|
dr1["controlWidth"] = 120;
|
|
dr1["controlHeight"] = 21;
|
|
dr1["rowspace"] = 5;
|
|
dt.Rows.Add(dr1);
|
|
}
|
|
|
|
private void simpleButton2_Click(object sender, EventArgs e)
|
|
{
|
|
int RowIndex = gridControl1.CurrentCell.RowIndex; //当前单元格所在行
|
|
DataTable dt = gridControl1.DataSource == null ? new DataTable() : gridControl1.DataSource as DataTable;//克隆DataTable结构
|
|
DataRow dr = dt.Rows[RowIndex];
|
|
if (dr == null)
|
|
return;
|
|
if (dt == null)
|
|
return;
|
|
DataGridViewRow row = gridControl1.Rows[RowIndex];
|
|
gridControl1.Rows.Remove(row);
|
|
}
|
|
|
|
private void simpleButton3_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult drt = MessageBox.Show("执行方案将覆盖现有布局,是否继续?", "询问", MessageBoxButtons.OKCancel);
|
|
if (drt != DialogResult.OK)
|
|
return;
|
|
|
|
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
if (dt == null)
|
|
return;
|
|
DataTable dtCol = gridControl1.DataSource as DataTable;
|
|
if (dtCol == null)
|
|
return;
|
|
if (dtCol.Rows.Count < 1)
|
|
{
|
|
MessageBox.Show("未添加栏目不能执行方案");
|
|
return;
|
|
}
|
|
|
|
foreach (DataRow drCol in dtCol.Rows)
|
|
{
|
|
int iCol = Convert.ToInt32(drCol["column_id"]);
|
|
int iLeft = Convert.ToInt32(drCol["controlLeft"]);
|
|
int iTop = Convert.ToInt32(drCol["controlTop"]);
|
|
int iWidth = Convert.ToInt32(drCol["controlWidth"]);
|
|
int iHeight = Convert.ToInt32(drCol["controlHeight"]);
|
|
int iSpace = Convert.ToInt32(drCol["rowspace"]);
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
if (Convert.ToInt32(dr["column_id"]) == iCol)
|
|
{
|
|
dr["controlLeft"] = iLeft;
|
|
dr["controlTop"] = iTop;
|
|
dr["controlWidth"] = iWidth;
|
|
dr["controlHeight"] = iHeight;
|
|
iTop = iTop + iHeight + iSpace;
|
|
}
|
|
}
|
|
}
|
|
|
|
dc._hostFrame.Controls.Clear();
|
|
dc._overlayer.Controls.Clear();
|
|
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
if (row["formkey"].ToString() == "")
|
|
continue;
|
|
string fieldid = row["fieldid"].ToString();
|
|
string username = row["username"].ToString();
|
|
string fieldtypeid = row["fieldtypeid"].ToString();
|
|
string fieldname = row["fieldname"].ToString();
|
|
string defaultValue = row["defaultValue"].ToString();
|
|
string column_id = row["column_id"].ToString();
|
|
int orderid = Convert.ToInt32(row["orderid"]);
|
|
Control ctr = ControlHelper.CreateControl(username, fieldname, Convert.ToInt32(fieldtypeid));
|
|
|
|
int posX = Convert.ToInt32(row["controlLeft"]);
|
|
int posY = Convert.ToInt32(row["controlTop"]);
|
|
int width = Convert.ToInt32(row["controlWidth"]);
|
|
int height = Convert.ToInt32(row["controlHeight"]);
|
|
int tabOrder = Convert.ToInt32(row["tabOrder"]);
|
|
|
|
|
|
if (ctr == null)
|
|
continue;
|
|
ctr.Location = (new Point(posX, posY));//屏幕坐标转换成控件容器坐标
|
|
ctr.Width = width;
|
|
ctr.Height = height;
|
|
ctr.TabIndex = tabOrder;
|
|
|
|
ctr.Tag = new object[] { fieldid, username, fieldtypeid, fieldname, defaultValue, column_id, orderid };
|
|
ctr.Parent = dc._hostFrame;
|
|
ctr.BringToFront();
|
|
}
|
|
}
|
|
|
|
private void toolStripMenuItem3_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult dlg = MessageBox.Show("是否按顺序号生成tab键次序?", "询问", MessageBoxButtons.YesNo);
|
|
if (dlg != DialogResult.Yes)
|
|
return;
|
|
|
|
gcFiled.SelectAll();
|
|
DataTable dt = gcFiled.DataSource == null ? new DataTable() : gcFiled.DataSource as DataTable;//克隆DataTable结构
|
|
List<DataRow> selRow = new List<DataRow>();
|
|
foreach (DataGridViewRow row in gcFiled.SelectedRows)
|
|
{
|
|
DataRow dr = (row.DataBoundItem as DataRowView).Row;//微软提供的唯一的转换DataRow
|
|
selRow.Add(dr);
|
|
}
|
|
foreach (DataRow dr in selRow)
|
|
{
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() != "")
|
|
{
|
|
int value = Convert.ToInt32(dr["orderid"]);
|
|
|
|
string ctlName = dr["fieldname"].ToString();
|
|
Control[] ctr = this.Controls.Find(ctlName, true);
|
|
if ((ctr == null) || (ctr.Length < 1))
|
|
{
|
|
continue;
|
|
}
|
|
ctr[0].TabIndex = value;
|
|
object[] objs = (object[])ctr[0].Tag;
|
|
objs[6] = value;
|
|
ctr[0].Tag = objs;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
gcFiled.ClearSelection();
|
|
}
|
|
|
|
private void MyFormDesigner_Resize(object sender, EventArgs e)
|
|
{
|
|
plRight.Height = this.Height;
|
|
plRight.Width = this.Width;
|
|
}
|
|
|
|
private void toolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult drt = MessageBox.Show("是否重新生成顺序号?", "询问", MessageBoxButtons.YesNo);
|
|
if (drt != DialogResult.Yes)
|
|
return;
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
string ctlName = "";
|
|
Control[] ctr = null;
|
|
int curRow = 1;
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
if (dr["formkey"].ToString() != "")
|
|
{
|
|
dr["orderid"] = curRow;
|
|
ctlName = dr["fieldname"].ToString();
|
|
ctr = this.Controls.Find(ctlName, true);
|
|
if ((ctr == null) || (ctr.Length < 1))
|
|
{
|
|
curRow = curRow + 1;
|
|
continue;
|
|
}
|
|
object[] objs = (object[])ctr[0].Tag;
|
|
objs[6] = curRow;
|
|
ctr[0].Tag = objs;
|
|
|
|
curRow = curRow + 1;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 按照分组设置
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemwordbooktab where formKey='{0}'", FrmKey));
|
|
List<DataRow> selRow = new List<DataRow>();
|
|
foreach (DataGridViewRow row in gcFiled.SelectedRows)
|
|
{
|
|
DataRow dr = (row.DataBoundItem as DataRowView).Row;//微软提供的唯一的转换DataRow
|
|
selRow.Add(dr);
|
|
}
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
FrmGroup frmGroup = new FrmGroup(DllCoid, selRow);
|
|
if (frmGroup.ShowDialog() == DialogResult.OK)
|
|
{
|
|
InitData();
|
|
}
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 按照分组设置
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSeparateColumn(object sender, EventArgs e)
|
|
{
|
|
ToolStripMenuItem tool = sender as ToolStripMenuItem;
|
|
int columnId = Convert.ToInt32(tool.Tag);
|
|
List<DataRow> selRow = new List<DataRow>();
|
|
DataTable dt = gcFiled.DataSource == null ? new DataTable() : gcFiled.DataSource as DataTable;//克隆DataTable结构
|
|
foreach (DataGridViewRow row in gcFiled.SelectedRows)
|
|
{
|
|
DataRow dr = (row.DataBoundItem as DataRowView).Row;//微软提供的唯一的转换DataRow
|
|
selRow.Add(dr);
|
|
}
|
|
foreach (DataRow dr in selRow)
|
|
{
|
|
if (dr == null)
|
|
return;
|
|
if (dr["formkey"].ToString() != "")
|
|
{
|
|
int value = columnId;
|
|
if (comboBox1.SelectedIndex == 1)
|
|
{
|
|
value = Convert.ToInt32(dr["column_id"]) + value;
|
|
}
|
|
dr["column_id"] = value;
|
|
|
|
string ctlName = dr["fieldname"].ToString();
|
|
Control[] ctr = this.Controls.Find(ctlName, true);
|
|
if ((ctr == null) || (ctr.Length < 1))
|
|
{
|
|
continue;
|
|
}
|
|
object[] objs = (object[])ctr[0].Tag;
|
|
objs[5] = columnId;
|
|
ctr[0].Tag = objs;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ToolStripMenuItemSzlm_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = gcFiled.DataSource as DataTable;
|
|
if (dt == null)
|
|
return;
|
|
dc._hostFrame.Controls.Clear();
|
|
dc._overlayer.Controls.Clear();
|
|
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
if (row["formkey"].ToString() == "")
|
|
continue;
|
|
string fieldid = row["fieldid"].ToString();
|
|
string username = row["username"].ToString();
|
|
string fieldtypeid = row["fieldtypeid"].ToString();
|
|
string fieldname = row["fieldname"].ToString();
|
|
string defaultValue = row["defaultValue"].ToString();
|
|
string column_id = row["column_id"].ToString();
|
|
int orderid = Convert.ToInt32(row["orderid"]);
|
|
Control ctr = ControlHelper.CreateControl(username, fieldname, Convert.ToInt32(fieldtypeid));
|
|
|
|
int posX = Convert.ToInt32(row["controlLeft"]);
|
|
int posY = Convert.ToInt32(row["controlTop"]);
|
|
int width = Convert.ToInt32(row["controlWidth"]);
|
|
int height = Convert.ToInt32(row["controlHeight"]);
|
|
int tabOrder = Convert.ToInt32(row["tabOrder"]);
|
|
|
|
|
|
if (ctr == null)
|
|
continue;
|
|
ctr.Location = (new Point(posX, posY));//屏幕坐标转换成控件容器坐标
|
|
ctr.Width = width;
|
|
ctr.Height = height;
|
|
ctr.TabIndex = tabOrder;
|
|
|
|
ctr.Tag = new object[] { fieldid, username, fieldtypeid, fieldname, defaultValue, column_id, orderid };
|
|
ctr.Parent = dc._hostFrame;
|
|
ctr.BringToFront();
|
|
}
|
|
}
|
|
|
|
//根据表格中内容修改全部TAB
|
|
private void btn_TAB_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
DataTable dt = gcFiled.DataSource == null ? new DataTable() : gcFiled.DataSource as DataTable;//克隆DataTable结构
|
|
DialogResult dlrg = MessageBox.Show("是否对全部控件的Tab进行批量调整?", "询问", MessageBoxButtons.YesNo);
|
|
if (dlrg != DialogResult.Yes)
|
|
return;
|
|
|
|
//int value = 1;
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
if (dr == null)
|
|
return;
|
|
if (dr["tabOrder"]+"" != "")
|
|
{
|
|
|
|
int value = Convert.ToInt32(dr["tabOrder"]);
|
|
string ctlName = dr["fieldname"].ToString();
|
|
Control[] ctr = this.Controls.Find(ctlName, true);
|
|
if ((ctr == null) || (ctr.Length < 1))
|
|
{
|
|
continue;
|
|
}
|
|
ctr[0].TabIndex = value;
|
|
//点击保存时去修改
|
|
//try
|
|
//{
|
|
// string sql = string.Format("update p_systemcontrollocation set tabOrder='{0}' where formKey='{1}' and fieldName='{2}'", value, dr["formKey"], dr["fieldName"]);
|
|
// SqlHelper.ExecuteNonQuery(sql);
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
//}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|