📄 addrelation.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using WorkFlow.util;
namespace WorkFlow.flow
{
/// <summary>
/// AddRelation 的摘要说明。
/// </summary>
public class AddRelation : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private RelationDef am=null;
private SqlConnection conn;
private System.Windows.Forms.ComboBox comboBox3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public AddRelation(RelationDef my)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.am=my;
if(conn==null)
conn = MainForm.getConnection();
this.initConf();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.comboBox3 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(136, 24);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 0;
this.comboBox1.Text = "请选择";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// comboBox2
//
this.comboBox2.Location = new System.Drawing.Point(320, 24);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 20);
this.comboBox2.TabIndex = 1;
this.comboBox2.Text = "请选择";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 6;
this.label1.Text = "定义步骤:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(264, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 7;
this.label2.Text = "与步骤:";
this.label2.Click += new System.EventHandler(this.label2_Click);
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 64);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(100, 16);
this.label5.TabIndex = 14;
this.label5.Text = "具有强制关系";
//
// button5
//
this.button5.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button5.Location = new System.Drawing.Point(136, 104);
this.button5.Name = "button5";
this.button5.TabIndex = 15;
this.button5.Text = "提交";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button6.Location = new System.Drawing.Point(224, 104);
this.button6.Name = "button6";
this.button6.TabIndex = 16;
this.button6.Text = "关闭";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// comboBox3
//
this.comboBox3.Location = new System.Drawing.Point(136, 64);
this.comboBox3.Name = "comboBox3";
this.comboBox3.Size = new System.Drawing.Size(121, 20);
this.comboBox3.TabIndex = 17;
this.comboBox3.Text = "请选择";
//
// AddRelation
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.AliceBlue;
this.ClientSize = new System.Drawing.Size(456, 141);
this.Controls.Add(this.comboBox3);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.label5);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.comboBox1);
this.Name = "AddRelation";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "定义流程约束关系";
this.ResumeLayout(false);
}
#endregion
private void initConf()
{
try
{
using(SqlCommand cmd = conn.CreateCommand())
{
string sql=" select seq, name,userid from t_flowstepmodeldef where flowid = "+this.am.flowid;
cmd.CommandText = sql;
using(SqlDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
string item=reader.GetString(1);
this.comboBox1.Items.Add(item);
this.comboBox2.Items.Add(item);
}
this.comboBox1.SelectedIndex=0;
this.comboBox2.SelectedIndex=0;
}
}
this.comboBox3.Items.Add("本人->本人");
this.comboBox3.Items.Add("下级->上级");
this.comboBox3.Items.Add("上级->下级");
this.comboBox3.Items.Add("下级->最高级");
}
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;
}
}
public int getUserid(string name)
{
try
{
string select = "select autoid from t_user where name='"+name+"'";
Console.WriteLine(select);
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
return reader.GetInt32(0);
}
}
}
return 0;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return 0;
}
}
public int getStepid(string name)
{
try
{
string select = "select seq from t_flowstepmodeldef where name='"+name+"' and flowid="+this.am.flowid;
Console.WriteLine(select);
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
return reader.GetInt32(0);
}
}
}
return 0;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return 0;
}
}
private void button6_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void button5_Click(object sender, System.EventArgs e)
{
if(!this.comboBox1.SelectedItem.ToString().Equals(this.comboBox2.SelectedItem.ToString()))
{
string fromstep= this.comboBox1.SelectedItem.ToString();
string tostep=this.comboBox2.SelectedItem.ToString();
int fromstepid=this.getStepid(fromstep);
int tostepid=this.getStepid(tostep);
if(this.comboBox3.SelectedIndex==0)
{
if(fromstepid==0&&tostepid==this.comboBox2.Items.Count)
{
int tmp=fromstepid;
fromstepid=tostepid;
tostepid=tmp;
}
}
int relation=this.comboBox3.SelectedIndex;
if(!this.isRelated(fromstepid,tostepid,relation))
{
string sql="insert into t_relation values('"+this.am.flowid+"','"+fromstepid+"','"+tostepid+"','"+relation+"',0)";
this.excute(sql);
}
this.am.dgRelation.DataBindings.Clear();
this.am.setRelation();
MessageBox.Show("添加流程关系完成");
}
else
{
MessageBox.Show("相同的步骤间定义强制关系没有意义啊");
}
}
private bool isRelated(int sfrom,int sto,int relation)
{
try
{
string select = "select * from t_relation where fromseq='"+sfrom+"' and toseq="+sto+" and relation="+relation+" and flowid="+this.am.flowid;
Console.WriteLine(select);
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
return true;
}
}
}
return false;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
}
private bool excute(string sql)
{
try
{
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
return true;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
}
private void label2_Click(object sender, System.EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//this.comboBox2.Items.Remove(this.comboBox1.SelectedItem);
this.comboBox2.Items.Clear();
for(int i=0;i<this.comboBox1.Items.Count;i++)
{
if(i==this.comboBox1.SelectedIndex)continue;
else this.comboBox2.Items.Add(this.comboBox1.Items[i]);
}
this.comboBox2.SelectedIndex=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -