📄 flowstepfinish.cs
字号:
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
sconn.Close();
}
}
public string getRealName(int autoid)
{
SqlConnection sconn=MainForm.getConnection();
try
{
string select = "select name,email from t_user where autoid="+autoid;
Console.WriteLine(select);
//this.conn.Close();
using(SqlCommand cmd = sconn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
return reader.GetString(0);
}
reader.Close();
}
}
return null;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
finally
{
sconn.Close();
}
}
public string getMail(int autoid)
{
SqlConnection sconn=MainForm.getConnection();
try
{
string select = "select email from t_user where autoid="+autoid;
Console.WriteLine(select);
using(SqlCommand cmd = sconn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
return reader.GetString(0);
}
reader.Close();
}
}
return null;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
finally
{
sconn.Close();
}
}
public int getUserid(string name)
{
try
{
string select = "select autoid from t_user where name='"+name+"'";
Console.WriteLine(select);
conn=this.getConnection();
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
return reader.GetInt32(0);
}
reader.Close();
}
}
return 0;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return 0;
}
}
public Hashtable getNextOper()
{
try
{
Hashtable hs=new Hashtable();
string select = " select distinct relation from t_flow a,t_flowstep b,t_relation c "+
" where a.FLOWID=c.FLOWID "+
" and a.AUTOID=b.PROJECTID "+
" and b.PROJECTID="+this.projectid+
" and b.SEQ="+(this.nextseq-1)+
" and b.SEQ=c.FROMSEQ ";
//先从数据库查询当前步骤到当前步骤的查询是否具有约束关系
SqlConnection sconn=MainForm.getConnection();
using(SqlCommand cmd = sconn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
int relation=reader.GetInt32(0);
switch(relation)
{
case 0://本人->本人关系
reader.Close();
select="select b.NAME from t_flowstep a,t_user b "+
" where a.PROJECTID= "+this.projectid+
" and a.SEQ=1 "+
" and a.OPERATORID=b.AUTOID ";
cmd.CommandText = select;
SqlDataReader reader0 = cmd.ExecuteReader();
if(reader0.Read())
{
hs.Add(reader0.GetString(0),"sss");
}
return hs;
case 1://下级->上级
reader.Close();
select="select c.NAME from t_dep a,t_user b,t_user c "+
"where a.DEPCODE=b.DEPCODE "+
"and a.PRINCIPALID=c.AUTOID "+
"and b.AUTOID="+MainForm.getUserAutoID();
cmd.CommandText = select;
SqlDataReader reader1 = cmd.ExecuteReader();
if(reader1.Read())
{
hs.Add(reader1.GetString(0),"sss");
}
return hs;
case 2://上级->下级
reader.Close();
select="select b.NAME from t_dep a,t_user b "+
"where a.DEPCODE=b.DEPCODE "+
"and a.PRINCIPALID="+MainForm.getUserAutoID();
cmd.CommandText = select;
SqlDataReader reader2 = cmd.ExecuteReader();
while(reader2.Read())
{
hs.Add(reader2.GetString(0),"sss");
}
return hs;
case 3://下级->部门最高级
reader.Close();
select="select c.NAME from t_dep a,t_user b,t_user c "+
"where instr(b.DEPCODE,a.DEPCODE)=1 "+
"and a.parentid=1001"+
"and a.PRINCIPALID=c.AUTOID "+
"and b.AUTOID="+MainForm.getUserAutoID();
cmd.CommandText = select;
SqlDataReader reader3 = cmd.ExecuteReader();
if(reader3.Read())
{
hs.Add(reader3.GetString(0),"sss");
}
return hs;
}
}
reader.Close();
}
}
if(hs!=null&&hs.Keys.Count>=1)
{
return hs;
}
else
{//不存在任何关系,则从流程模板里面选择 模板定义时指定的该步骤的操作者
select="select userid from t_flowstepmodeldef,t_flow,t_flowstep where t_flowstep.projectid=t_flow.autoid "+
" and t_flow.flowid=t_flowstepmodeldef.flowid "+
" and t_flow.autoid="+this.projectid+
" and t_flowstepmodeldef.seq="+this.nextseq;
Console.WriteLine(select);
using(SqlCommand cmd = sconn.CreateCommand())
{
cmd.CommandText = select;
using(SqlDataReader reader = cmd.ExecuteReader())
{
if(reader.Read())
{
string opuser=reader.GetString(0);
if(opuser!=null)
{
string []users=opuser.Split(',');
foreach(string user in users)
{
if(user!=null&&!user.Equals(""))
hs.Add(this.getRealName(int.Parse(user)),"s");
}
}
}
reader.Close();
return hs;
}
}
}
sconn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
}
public SqlConnection getConnection()
{
try
{
if(conn==null)
conn = MainForm.getConnection();
return conn;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
}
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection sconn=MainForm.getConnection();
if(this.textBox1.Text.Equals(""))
{
MessageBox.Show("请完成以后再提交");
return;
}
string sql="update t_flowstep set content='"+this.textBox1.Text+"',status=1,modifydate=getdate() where projectid="+
this.projectid+" and seq="+(this.nextseq-1);
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
if(!(this.getMaxStep()<this.nextseq))
{
sql="update t_flowstep set operatorid ="+this.nextoper+" where projectid="+
this.projectid+" and seq="+(this.nextseq);
//SqlConnection sconn=MainForm.getConnection();
using(SqlCommand cmd = sconn.CreateCommand())
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
}
else
{
sql="update t_flow set status=1 where autoid="+this.projectid;
using(SqlCommand cmd = sconn.CreateCommand())
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
}
this.ff.dataGrid1.DataBindings.Clear();
this.ff.setUserMustDo();
if(this.comboBox1.Enabled)
{
this.commitMail();
}
MessageBox.Show("提交成功");
sconn.Close();
this.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.nextoper=getUserid(this.comboBox1.SelectedItem.ToString());
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
private void commitMail()
{
string from=this.getMail(MainForm.getUserAutoID());
string fromname=(MainForm.getRealName());
int toid=this.getUserid(this.comboBox1.SelectedItem.ToString());
string to=this.getMail(toid);
string toname=this.comboBox1.SelectedItem.ToString();
string subject="流程【"+this.flowname+"】需要您去填写第【"+this.nextseq+"】步【"+getNextRealName()+"】";
string body="该流程前面已经填写内容\n";
body+=this.richTextBox1.Text+"\n";
body+="第"+(this.nextseq-1)+"步:"+this.currentname+"\n" ;
body+="操作者:"+MainForm.getRealName()+"\n" ;
body+="填写日期:"+System.DateTime.Now+"\n" ;
body+=this.textBox1.Text;
body=body.Replace("\n","<BR>");
WorkFlow.util.SendMail.sendmail(from,fromname,subject,toname,to,body);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -