📄 frmsetconfig.cs
字号:
//
// ultraLabel2
//
appearance14.TextVAlign = DS.Win.VAlign.Middle;
this.ultraLabel2.Appearance = appearance14;
this.ultraLabel2.Location = new System.Drawing.Point(208, 32);
this.ultraLabel2.Name = "ultraLabel2";
this.ultraLabel2.Size = new System.Drawing.Size(64, 23);
this.ultraLabel2.TabIndex = 5;
this.ultraLabel2.Text = "脚本文件:";
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(192, 360);
this.btnDelete.Name = "btnDelete";
this.btnDelete.TabIndex = 7;
this.btnDelete.Text = "删除";
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(312, 360);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 8;
this.btnClose.Text = "关闭";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// gbAdd
//
this.gbAdd.Controls.Add(this.ddlFileName);
this.gbAdd.Controls.Add(this.txtDisplayName);
this.gbAdd.Controls.Add(this.ultraLabel1);
this.gbAdd.Controls.Add(this.ultraLabel2);
this.gbAdd.Dock = System.Windows.Forms.DockStyle.Top;
this.gbAdd.Location = new System.Drawing.Point(0, 272);
this.gbAdd.Name = "gbAdd";
this.gbAdd.Size = new System.Drawing.Size(464, 72);
this.gbAdd.SupportThemes = false;
this.gbAdd.TabIndex = 9;
this.gbAdd.Text = "添加";
//
// ddlFileName
//
this.ddlFileName.Location = new System.Drawing.Point(288, 32);
this.ddlFileName.Name = "ddlFileName";
this.ddlFileName.Size = new System.Drawing.Size(152, 20);
this.ddlFileName.TabIndex = 7;
//
// FrmSetConfig
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(464, 414);
this.Controls.Add(this.gbAdd);
this.Controls.Add(this.ultraGroupBox2);
this.Controls.Add(this.ultraGroupBox1);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.btnDelete);
this.Controls.Add(this.btnClose);
this.MaximizeBox = false;
this.Name = "FrmSetConfig";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "设置";
this.Load += new System.EventHandler(this.FrmSetConfig_Load);
((System.ComponentModel.ISupportInitialize)(this.ultraGroupBox1)).EndInit();
this.ultraGroupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.ultraGroupBox2)).EndInit();
this.ultraGroupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgFile)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.gbAdd)).EndInit();
this.gbAdd.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void FrmSetConfig_Load(object sender, System.EventArgs e)
{
InitPopulate();
}
private void InitPopulate()
{
LoadDg();
#region 加载下拉框
IList list = new ArrayList();
string filePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\Resources\\SCRIPT\\";
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(filePath);
System.IO.FileInfo[] files = dirInfo.GetFiles("*.sql");
foreach(System.IO.FileInfo file in files)
{
KeyValueField item = new KeyValueField();
item.Key = file.Name;
item.Value = file.Name;
list.Add(item);
}
this.ddlFileName.DataSource = list;
this.ddlFileName.DisplayMember = "Value";
this.ddlFileName.ValueMember = "Key";
this.ddlFileName.SelectedItem = null;
#endregion
}
private void LoadDg()
{
if(this.rbtInitData.Checked)
{
this.configFileName = "InitDataConfig.xml";
this.nodeName = "InitDataScript";
}
else
{
this.configFileName = "OptimizeConfig.xml";
this.nodeName = "OptimizeScript";
}
DataTable dt = GlobalObject.Instance.LocalSession.GetConfigs(this.configFileName,this.nodeName);
dt.Columns.Add("Select",typeof(bool));
foreach(DataRow row in dt.Rows)
{
row["Select"] = false;
}
this.dgFile.DataSource = dt;
this.dgFile.DataBind();
}
private bool RepeatCheck()
{
bool result = false;
DataTable dt = (DataTable)this.dgFile.DataSource;
foreach(DataRow row in dt.Rows)
{
if(row["DisplayName"].ToString() == this.txtDisplayName.Text.Trim()
|| row["FileName"].ToString() == this.ddlFileName.SelectedValue.ToString())
{
MessageBox.Show("记录已存在!");
result = true;
break;
}
}
return result;
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
if(this.txtDisplayName.Text.Trim() == string.Empty)
{
MessageBox.Show("脚本名称不能为空!");
return;
}
if(this.ddlFileName.SelectedValue == null )
{
MessageBox.Show("请选择脚本文件!");
return;
}
if(RepeatCheck()) return;
string[] attrib = {"DisplayName", "FileName"};
string[] attribContent = {this.txtDisplayName.Text.Trim(),this.ddlFileName.SelectedValue.ToString()};
try
{
GlobalObject.Instance.LocalSession.InsertNode(this.configFileName,"configuration",this.nodeName,attrib,attribContent,"");
LoadDg();
MessageBox.Show("添加成功!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"执行失败",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
if(this.ConfigChangEvent!= null)
this.ConfigChangEvent(this.configFileName);
}
private void rbtInitData_CheckedChanged(object sender, System.EventArgs e)
{
LoadDg();
}
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
bool isCheck = false;
IList nodes = new ArrayList();
foreach(DS.Win.UltraWinGrid.UltraGridRow row in this.dgFile.Rows)
{
if((Boolean)row.Cells["Select"].Value == true)
{
isCheck = true;
string displayName = row.Cells["DisplayName"].Value.ToString();
string node = "configuration/"+this.nodeName+"[@DisplayName='"+displayName+"']";
nodes.Add(node);
}
}
if(!isCheck)
{
MessageBox.Show("请选择要删除的记录!");
return;
}
if(MessageBox.Show("确认删除?", "",MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
foreach(string node in nodes)
{
GlobalObject.Instance.LocalSession.DeleteNode(this.configFileName,node,null,null);
}
LoadDg();
if(this.ConfigChangEvent!= null)
this.ConfigChangEvent(this.configFileName);
}
}
public class KeyValueField
{
private string _key;
private string _value;
public string Key
{
get
{
return this._key;
}
set
{
this._key = value;
}
}
public string Value
{
get
{
return this._value;
}
set
{
this._value = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -