第八章 启动与执行业务流程(八)

8.2 启动与执行业务流程

8.2.2 TaskInstance.aspx.cs文件代码

          ......(续前页)

          //保存附件

          bool SaveAttached(string processinstanceid,string relatedtable,

               

 string identityfield,string fieldvalue)
          {
              SqlParameter pimage;
              SqlParameter pimagetype;

              //获取文件上传html控件组
              HttpFileCollection files = HttpContext.Current.Request.Files;
              int imagesize;
              string imagetype;
              Stream imagestream;
              string attachedname;
              for(int i=0;i<files.Count;i++)
              {
                 HttpPostedFile ofile = files[i];
                 imagesize=ofile.ContentLength;
                 if(imagesize>0)
                 {

                    //获取上传文件后缀(扫描图片文件或word转pdf文件)
                    string fileExt = Path.GetExtension(ofile.FileName).ToLower() ;
                    if (fileExt != ".jpg" & fileExt != ".jpeg" & fileExt != ".gif"

                          & fileExt != ".png" & fileExt !=".pdf")
                    {
                       Label1.Text = Path.GetFileName(ofile.FileName)

                          +"不是jpg,jpeg,gif,png,pdf格式的文件,未上传成功.请重新上传该文件!";
                       return false;
                    }
                    attachedname=Request.Form["filename"+(i+1)].Trim();
                    if(attachedname == "")
                    {
                       Label1.Text="附件名称不能为空";
                       return false;
                    }
                    Regex reg=new Regex(@"^[\u4e00-\u9fa5]*\w*$");//汉字或字母下划线
                    if(! reg.IsMatch(attachedname))
                    {
                       Label1.Text="请输入正确格式的附件名称";
                       return false;
                       
                    imagetype=ofile.ContentType;
                    imagestream=ofile.InputStream;

                    byte[] imagecotent=new byte[imagesize];
                    int intstatus;
                    intstatus=imagestream.Read(imagecotent,0,imagesize);

                    //sql参数名在一个事务的sql语句串中要唯一,否则出错.在这里通过i区分一下.
                    string strSql="insert into RelatedAttachedImages values

                       ('"+attachedname+"',"+processinstanceid+",'"+relatedtable+"','"

                        +identityfield+"',"+fieldvalue+",@AttachedImage"+i+",@ImageType"+i

                        +","+ViewState["taskinstanceid"].ToString()+")";
                    SqlCommand mycommand=new SqlCommand();
                    mycommand.CommandText=strSql;   
                    pimage=new SqlParameter("@AttachedImage"+i, SqlDbType.Image);
                    pimage.Value=imagecotent;
                    mycommand.Parameters.Add(pimage);

                    pimagetype=new SqlParameter("@ImageType"+i, SqlDbType.VarChar, 30);
                    pimagetype.Value=imagetype;
                    mycommand.Parameters.Add(pimagetype);

                    //将附件名称与内容写入数据库
                    Base basecode=new Base();
                    if(! basecode.SQLExeNonQuery_proc(mycommand))
                    {
                       Label1.Text=basecode.BaseSqlErrDes;
                       return false;
                    }
                 }//if(imagesize>0)
              }//for
              return true;
           }

           //保存留言(点击完成任务按钮时调用)
           bool saveMessage(string processinstanceid)
           {
              string strSql="update ProcessInstance set Message=@Message where

                      ProcessInstanceID="+processinstanceid;
              SqlCommand mycommand=new SqlCommand();
              mycommand.CommandText=strSql;
              Base basecode=new Base();
              try
              {

                 //员工姓名
                 strSql="select EmployeeName from Employees where EmployeeID=(select

                      EmployeeID from Users where UserID="+Session["userid"].ToString ()+")";
                 DataSet myds=basecode.SQLExeDataSet(strSql);
                 string employeename=myds.Tables[0].Rows[0]["EmployeeName"].ToString();

                 //任务环节名称
                 string taskname=ds.Tables[0].Rows[0]["TaskName"].ToString();

                 mycommand.Parameters.Add(new SqlParameter("@Message",SqlDbType.VarChar));

                 //累加审核信息(沟通栏信息),格式为员工姓名(任务名):留言
                 if(ds.Tables[1].Rows[0]["Message"] != DBNull.Value)
                     mycommand.Parameters["@Message"].Value=ds.Tables[1].Rows[0]["Message"]

                      .ToString()+employeename+"("+taskname+"):"+TextBox1.Text.Trim()+"<br>";
                 else
                     mycommand.Parameters["@Message"].Value

                          =employeename+"("+taskname+"):"+TextBox1.Text.Trim()+"<br>";
                 if(! basecode.SQLExeNonQuery_proc(mycommand))
                 {
                    Label2.Text="9:"+basecode.BaseSqlErrDes;
                    return false;
                 }
              }
              catch(System.FormatException exp)
              {
                 Label2.Text="10:"+exp.Message;
                 return false;
              }
              //清空临时保存的留言
              strSql="select * from TempSavedMessage where ProcessInstanceID="

                    +processinstanceid+" and UserID="+Session["userid"].ToString ();
              if(new Base().IfExistRecord(strSql))
                   strSql="delete from TempSavedMessage where ProcessInstanceID="

                        +processinstanceid+" and UserID="+Session["userid"].ToString ();
              if(! basecode.SQLExeNonQuery(strSql))
              {
                 Label2.Text="9:"+basecode.BaseSqlErrDes;
                 return false;
              }
              return true;
           

           //点击保存按钮时临时保存留言到TempSavedMessage表
           bool saveTempMessage(string processinstanceid)
           {
              string strSql="select * from TempSavedMessage where ProcessInstanceID="

                        +processinstanceid+" and UserID="+Session["userid"].ToString ();
              if(new Base().IfExistRecord(strSql))
                 strSql="update TempSavedMessage set TempMessage=@TempMessage where

                      ProcessInstanceID="+processinstanceid+" and UserID="

                       +Session["userid"].ToString ();
              else
                 strSql="insert into TempSavedMessage(ProcessInstanceID,UserID,TempMessage)

                      values("+processinstanceid+","+Session["userid"].ToString ()

                        +",@TempMessage)";
              SqlCommand mycommand=new SqlCommand();
              mycommand.CommandText=strSql;
              Base basecode=new Base();
              try
              {
                 mycommand.Parameters.Add(new SqlParameter("@TempMessage",SqlDbType.VarChar));
                 mycommand.Parameters["@TempMessage"].Value=TextBox1.Text.Trim();
                 if(! basecode.SQLExeNonQuery_proc(mycommand))
                 {
                    Label2.Text="9:"+basecode.BaseSqlErrDes;
                    return false;
                 }
              }
              catch(System.FormatException exp)
              {
                 Label2.Text="10:"+exp.Message;
                 return false;
              }
              return true;
           }

           //删除当前用户上传的附件
           private void lbn_Click(object sender, EventArgs e)
           {
              LinkButton lbn=(LinkButton)sender;
              string imageid=lbn.ID;
              string strSql="delete RelatedAttachedImages where ImageID="+imageid;
              Base basecode=new Base();
              if(! basecode.SQLExeNonQuery(strSql))
              {
                 Label2.Text="11:"+basecode.BaseSqlErrDes;
                 return;
              }
              Response.Redirect("TaskInstance.aspx?id="

                    +ViewState["taskinstanceid"].ToString());
           }

           //打印表格按钮方法
           private void printedtablebutton_Click(object sender, EventArgs e)
           {
              LinkButton lbn=(LinkButton)sender;
              string bnid=lbn.ID;
              string printedtableid=bnid.Substring(3);//去掉前面的"lbn".
              //获取业务表数据
              string relatedtable=ds.Tables[1].Rows[0]["RelatedTable"].ToString();
              string identityfield=identityname.Tables[0].Rows[0]["IdentifiedField"]

                   .ToString();
              string fieldvalue=ds.Tables[1].Rows[0]["IdentityFieldValue"].ToString();
              string processinstanceid=ds.Tables[1].Rows[0]["ProcessInstanceID"].ToString();
              //在打印表格前要先保存可写字段值(否则可能打印表格中有关当前编辑字段的部分无值)
              if(! Savefields(relatedtable,identityfield,fieldvalue,processinstanceid))
              {
                 Label2.Text="12:"+Label2.Text+" 发生保存业务表错误!不能打印表格";
                 return;
              }
              //处理附件上传(不加该功能的话显示打印表格后上传文件控件的内容消失)
              if(ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim() == "L"

                  || ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim() == "LR")
              {
                 if(! SaveAttached(processinstanceid,relatedtable,identityfield,fieldvalue))
                 {
                    Label2.Text="13:"+Label2.Text+" 发生上传附件错误!不能打印表格";
                    return;
                 }
              }
              Response.Write("<script type='text/javascript'>window.open('PrintTable.aspx?id="

                    +printedtableid+"&fieldvalue="+fieldvalue+"')</script>");

              //重指向页面后,如果需要,用户还可以删除刚上传的附件

              Response.Redirect("TaskInstance.aspx?id="+ViewState["taskinstanceid"]

                    .ToString());
           }

           //回退按钮
           private void Button3_Click(object sender, System.EventArgs e)
           {
              //获取业务表数据
              string relatedtable=ds.Tables[1].Rows[0]["RelatedTable"].ToString();
              string identityfield=identityname.Tables[0].Rows[0]["IdentifiedField"]

                   .ToString();
              string fieldvalue=ds.Tables[1].Rows[0]["IdentityFieldValue"].ToString();
              string processinstanceid=ds.Tables[1].Rows[0]["ProcessInstanceID"].ToString();
              //保存可写字段值
              if(! Savefields(relatedtable,identityfield,fieldvalue,processinstanceid))
                  return;
              //保存留言
              if(! saveMessage(processinstanceid))
                  return;
              //处理附件上传
              if(ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim() == "L"

                  || ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim() == "LR")
              {
                  if(! SaveAttached(processinstanceid,relatedtable,identityfield,fieldvalue))
                     return;
              }
              //判断流程是否已经被冻结(防止在此时管理员刚进行了冻结操作),如果已经冻结则不再

              //执行后续操作。
              string strSql="select IsSuspended from ProcessInstance where ProcessInstanceID="

                              +processinstanceid;
              Base basecode=new Base();
              DataSet suspendds=basecode.SQLExeDataSet(strSql);
              if(suspendds.Tables[0].Rows[0]["IsSuspended"].ToString()=="Y")
                   Response.Redirect("TaskInstanceList.aspx");   
              //修改IsPostBack
              string postbackedtaskinstanceid=DropDownList1.SelectedValue;
              TaskInstanceClass taskins=new TaskInstanceClass();
              string taskinstanceid=ViewState["taskinstanceid"].ToString();
              //修改当前实例状态,结束当前任务的执行.
              taskins.UpDateTaskInstanceState(taskinstanceid,"Completed");
              //修改选择回退的任务实例状态,使其得以重新执行.
              taskins.UpDateTaskInstanceState(postbackedtaskinstanceid,"Running");   
              Response.Redirect("TaskInstanceList.aspx");
           }

           //浏览留言信息按钮的事件处理方法

           private void LinkButton1_Click(object sender, System.EventArgs e)
           {
               string strlink="<script>window.open('DisplayMessage.aspx?id="

                    +ViewState["processinstanceID"].ToString()

                    +"','newwindow','height=400,width=600,top=0,left=0,toolbar=no,

                     menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>";
               Response.Write(strlink);
           }

           ......(待续)

           //附DisplayMessage.aspx.cs文件的主要代码(DisplayMessage.aspx只有自动生成的代码)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值