📄 relationdef.cs
字号:
this.dgFlow.PreferredRowHeight = 5;
this.dgFlow.ReadOnly = true;
this.dgFlow.RowHeadersVisible = false;
this.dgFlow.Size = new System.Drawing.Size(258, 279);
this.dgFlow.TabIndex = 0;
this.dgFlow.CurrentCellChanged += new System.EventHandler(this.dgFlow_CurrentCellChanged_1);
//
// splitter2
//
this.splitter2.Location = new System.Drawing.Point(264, 0);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(3, 299);
this.splitter2.TabIndex = 5;
this.splitter2.TabStop = false;
//
// RelationManager
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.AliceBlue;
this.ClientSize = new System.Drawing.Size(640, 454);
this.Controls.Add(this.splitter2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Name = "RelationManager";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "定义流程约束关系";
this.Load += new System.EventHandler(this.RelationManager_Load);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgFlowRelation)).EndInit();
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgRelation)).EndInit();
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgFlow)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void RelationManager_Load(object sender, System.EventArgs e)
{
try
{
userAutoId = MainForm.getUserAutoID();
if(conn==null)
conn = MainForm.getConnection();
setHash();
setdgFlow();
if(this.flowid==-1)
this.button1.Enabled=false;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
private void setHash()
{
try
{
hash=new Hashtable();
string select = "select autoid,name from t_user ";
Console.WriteLine(select);
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
hash.Add(reader.GetInt32(0)+"",reader.GetString(1));
}
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
// private void setFlowStep()
// {
// try
// {
// string select = " ";
// using(SqlDataAdapter adp = new SqlDataAdapter(select,conn))
// {
// DataTable dt = new DataTable();
// adp.Fill(dt);
// this.dgFlow.DataSource = dt;
// }
// }
// catch(Exception ex)
// {
// MessageBox.Show(ex.ToString());
// return;
// }
// }
//
private void setdgFlow()
{
try
{
string select = " select autoid 编号, name 模板名称, addtime 添加时间 from t_flowmodeldef where status = 0 and userautoid = "+userAutoId;
using(SqlDataAdapter adp = new SqlDataAdapter(select,conn))
{
DataTable dt = new DataTable();
adp.Fill(dt);
this.dgFlow.DataSource = dt;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
public void setRelation()
{
try
{
DataTable dt = new DataTable("relation");
dt.Columns.Add("from");
dt.Columns.Add("to");
dt.Columns.Add("srelation");
using(SqlCommand cmd = conn.CreateCommand())
{
string sql= " select distinct a.NAME,b.name,relation from t_relation,t_flowstepmodeldef a, t_flowstepmodeldef b "+
" where a.seq=t_relation.fromseq "+
" and b.seq=t_relation.toseq "+
" and t_relation.flowid=a.flowid "+
" and t_relation.flowid=b.flowid "+
" and t_relation.flowid= "+this.flowid;
cmd.CommandText =sql;
Console.WriteLine(sql);
using(SqlDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
DataRow dr= dt.NewRow();;
dr[0]=reader.GetString(0);
dr[1]=reader.GetString(1);
int relation=reader.GetInt32(2);
switch(relation)
{
case 0:dr[2]="本人->本人";break;
case 1:dr[2]="下级->上级";break;
case 2:dr[2]="上级->下级";break;
case 3:dr[2]="下级->部门最高领导";break;
}
dt.Rows.Add(dr);
}
DataSet ds=new DataSet();
ds.Tables.Add(dt);
this.dgRelation.SetDataBinding(ds,"relation");
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
private void dgFlow_CurrentCellChanged(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)this.dgFlow.DataSource;
if(dt==null || dt.Rows.Count==0)
return;
this.flowid = int.Parse(this.dgFlow[this.dgFlow.CurrentCell.RowNumber,0].ToString());
setOtherDg();
setRelation();
}
private void setOtherDg()
{
try
{
DataTable dt = new DataTable("flowrelation");
dt.Columns.Add("seq");
dt.Columns.Add("name");
dt.Columns.Add("idlist");
dt.Columns.Add("userid");
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = " select seq, name , userid from t_flowstepmodeldef where flowid = "+this.flowid +" order by seq";
using(SqlDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
DataRow dr= dt.NewRow();;
dr[0]=reader.GetInt32(0);
dr[1]=reader.GetString(1);
string list=reader.GetString(2);
string[] str=list.Split(',');
string slist="";
foreach(string key in str)
{
if(hash.ContainsKey(key))
slist+=hash[key]+",";
}
dr[2]=slist;
dr[3]=list;
dt.Rows.Add(dr);
}
DataSet ds=new DataSet();
ds.Tables.Add(dt);
this.dgFlowRelation.SetDataBinding(ds,"flowrelation");
if(this.flowid!=-1)
this.button1.Enabled=true;
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
public string getRealName(int autoid)
{
try
{
string select = "select name from t_user where autoid="+autoid;
Console.WriteLine(select);
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
return reader.GetString(0);
}
}
}
return null;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
}
private void dgFlow_CurrentCellChanged_1(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)this.dgFlow.DataSource;
if(dt==null || dt.Rows.Count==0)
return;
this.flowid = int.Parse(this.dgFlow[this.dgFlow.CurrentCell.RowNumber,0].ToString());
setOtherDg();
setRelation();
}
private void button1_Click(object sender, System.EventArgs e)
{
AddRelation ar=new AddRelation(this);
ar.ShowDialog();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -