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

来源:互联网 发布:淘宝客服年度总结 编辑:程序博客网 时间:2024/06/05 00:55

8.1 对业务过程定义的细化  

    UpdateTaskDefinition.aspx.cs文件代码:

            ......(续前页)

              //</可写字段控件集>    
              //在可读字段控件集与可写字段控件集之间增加一行间隔
              tr=new TableRow();
              tr.Height=16;
              tc=new TableCell();
              tc.ColumnSpan=10;
              tr.Cells.Add(tc);
              Tbl.Rows.Add(tr);
              tr=new TableRow();
              tc=new TableCell();
              tc.Text="可编辑字段:";
              tc.HorizontalAlign=HorizontalAlign.Right;
              tr.Cells.Add(tc);

              //为每一个关联字段设置单选框,并将"字段名+w"作为它的ID.
              chk=null;
              lb=null;
              for(int i=0;i<ds3.Tables[0].Rows.Count;i++)
              {
                 if((i% 8) == 0 & i>0)
                 {
                   tc=new TableCell();
                   tc.Text="&nbsp;&nbsp;&nbsp;";
                   tr.Cells.Add(tc);
                   Tbl.Rows.Add(tr);
                   tr=new TableRow();
                   tc=new TableCell();
                   tr.Cells.Add(tc);
                 }

                 tc=new TableCell();
                 tc.HorizontalAlign=HorizontalAlign.Right;
                 lb=new Label();
                 lb.Text=ds3.Tables[0].Rows[i]["FieldAlias"].ToString();
                 tc.Controls.Add(lb);
                 chk=new CheckBox();
                 chk.ID=ds3.Tables[0].Rows[i]["FieldName"].ToString()+"_w";

                 //如果是标识字段则默认钩选并不可编辑.
                 if(ds3.Tables[0].Rows[i]["IsIdentity"].ToString() =="Y")
                 {
                    chk.Checked=false;
                    chk.Enabled=false;
                 }
                 tc.Controls.Add(chk);
                 tr.Cells.Add(tc);
              }
              //最后一行列ColumnSpan设置为最大值.
              tc=new TableCell();
              tc.ColumnSpan=9;
              tr.Cells.Add(tc);
              Tbl.Rows.Add(tr);

              //如果记录中已有可读字段的内容,要分割字符串,得到字段名并设置对应控件的钩选.
              string writablefieldsstr="";
              if(ds.Tables[0].Rows[0]["WritableFields"] !=DBNull.Value)
                 writablefieldsstr=ds.Tables[0].Rows[0]["WritableFields"].ToString().Trim();
              if(writablefieldsstr != "")
              {
                string[] refieldsarray=new Tools().StringSplit(writablefieldsstr,",");
                for(int j=0;j<refieldsarray.Length;j++)
                {
                  //由于保存字段名字符串时最后还多一个",",所以要判断.
                  if(refieldsarray[j] !="")
                  {
                     chk=(CheckBox)this.FindControl(refieldsarray[j]+"_w");
                     if(chk !=null)
                        chk.Checked=true;
                  }
                }
              }
              ///</可编辑字段控件集>   
              //任务完成期限(天数)
              tr=new TableRow();
              tc=new TableCell();
              tc.Text="任务完成期限(天数):";
              tc.HorizontalAlign=HorizontalAlign.Right;
              tr.Cells.Add(tc);
              tc=new TableCell();
              tx=new TextBox();
              tx.ID="Due_Date";

              tx.Columns=3;
              tx.Text=ds.Tables[0].Rows[0]["DueDate"].ToString();
              tc.Controls.Add(tx);
              tc.ColumnSpan=9;
              tr.Cells.Add(tc);
              Tbl.Rows.Add(tr);

              //选择任务要打印的表格
              strSql="select PrintedTableID,PrintedTableName from PrintedTable where

                   RelatedTable='"+relatedtablename+"'";
              DataSet printedtableds=basecode.SQLExeDataSet(strSql);
              ViewState["printedtableds"]=printedtableds;//保存要打印的表格集合供后面使用
              tr=new TableRow();
              tc=new TableCell();
              tc.Text="选择要打印的表格:";
              tc.HorizontalAlign=HorizontalAlign.Right;
              tr.Cells.Add(tc);
              //为每一个与当前业务表关联的打印表格设置单选框,并将字段名作为它的ID.
              for(int i=0;i<printedtableds.Tables[0].Rows.Count;i++)
              {
                 //8个表格选择控件为一行
                 if((i% 8) == 0 & i>0)
                 {
                    //一行尾部加一列
                    tc=new TableCell();
                    tc.Text="&nbsp;&nbsp;&nbsp;";
                    tr.Cells.Add(tc);
                    //另起一行并加一列空白列
                    Tbl.Rows.Add(tr);
                    tr=new TableRow();
                    tc=new TableCell();
                    tr.Cells.Add(tc);
                 }

                 tc=new TableCell();
                 tc.HorizontalAlign=HorizontalAlign.Right;
                 lb=new Label();
                 lb.Text=printedtableds.Tables[0].Rows[i]["PrintedTableName"].ToString();
                 tc.Controls.Add(lb);
                 chk=new CheckBox();

                 //为避免出现ID重复错误
                 chk.ID="printedtable"

                          +printedtableds.Tables[0].Rows[i]["PrintedTableID"].ToString();
                 tc.Controls.Add(chk);
                 tr.Cells.Add(tc);
               }
               //最后一行列ColumnSpan设置为最大值.
               tc=new TableCell();
               tc.ColumnSpan=9;
               tr.Cells.Add(tc);
               Tbl.Rows.Add(tr);
               //如果当前任务定义中已有要打印表格,要分割字符串,得到表格ID并设置对应控件的钩选.
               string printedtablestr="";
               if(ds.Tables[0].Rows[0]["PrintedTable"] !=DBNull.Value)
                   printedtablestr=ds.Tables[0].Rows[0]["PrintedTable"].ToString().Trim();
               if(printedtablestr != "")
               {
                  string[] printedtablearray=new Tools().StringSplit(printedtablestr,",");

                  //j<printedtablearray.Length-1因为数组最后一项为空字符串
                  for(int j=0;j<printedtablearray.Length-1;j++)
                  {
                     chk=(CheckBox)this.FindControl("printedtable"+printedtablearray[j]);
                     if(chk !=null)
                        chk.Checked=true;
                  }
                   
            }//Page_Load()

            //保存任务按钮
            private void Button1_Click(object sender, System.EventArgs e)
            {
               if(SaveTaskDefinition())
                   Response.Redirect("TaskDefinitionList.aspx?id="

                                +ViewState["processid"].ToString());
               else
                   return;
            }

            //保存任务(增加了返回变量,否则保存按钮总是转向任务列表,将不能显示错误).
            bool SaveTaskDefinition()
            {
               //判断任务名称是否重复
               string taskdefname=((TextBox)this.FindControl("TaskName")).Text.Trim();
               if(taskdefname == "")
               {
                  Label2.Text="任务名不能为空";
                  return false;
               }
               TaskDefinitionClass taskdef=new TaskDefinitionClass();
               if(taskdef.IsExistedTaskName(taskdefname,ViewState["taskid"].ToString(),

                     ViewState["processid"].ToString()))
               {
                  Label2.Text="当前流程已存在该任务名";
                  return false;
               }
               //获取字段单选框列表的值
               string taskid=ViewState["taskid"].ToString();
               string readchkedfields="";
               string writechkedfields="";
               DataSet ds=(DataSet)ViewState["RelatedTablesFields"];
               for(int i=0;i<ds.Tables[0].Rows.Count;i++)
               {
                   CheckBox chk=(CheckBox)this.FindControl(ds.Tables[0]

                            .Rows[i]["FieldName"].ToString()+"_R");
                   if(chk.Checked & ds.Tables[0].Rows[i]["IsIdentity"].ToString() !="Y")
                       readchkedfields=

                          readchkedfields+ds.Tables[0].Rows[i]["FieldName"].ToString()+",";

                   CheckBox chk1=(CheckBox)this.FindControl(ds.Tables[0]

                          .Rows[i]["FieldName"].ToString()+"_w");
                   if(chk1.Checked & ds.Tables[0].Rows[i]["IsIdentity"].ToString() !="Y")
                       writechkedfields=

                           writechkedfields+ds.Tables[0].Rows[i]["FieldName"].ToString()+",";
                 
               //获取选择的要打印的表格
               string printedtable="";
               DataSet printedtableds=(DataSet)ViewState["printedtableds"];
               for(int i=0;i<printedtableds.Tables[0].Rows.Count;i++)
               {
                   CheckBox chk=(CheckBox)this.FindControl("printedtable"

                        +printedtableds.Tables[0].Rows[i]["PrintedTableID"].ToString());
                   if(chk.Checked)
                       printedtable=printedtable+printedtableds.Tables[0]

                            .Rows[i]["PrintedTableID"].ToString()+",";
               }

               string strSql;
               SqlCommand cmd;
               Base basecode=new Base();   
               //修改任务定义表记录
               strSql="update TaskDefinition set NodeType='TaskNode', TaskName=@TaskName,

                        AssignedRole=@AssignedRole,AboutAttached=@AboutAttached,

                         Readablefields=@Readablefields,WritableFields=@WritableFields,

                             DueDate=@DueDate,PrinTedTable=@PrintedTable

                                  where TaskID="+taskid;
               cmd=new SqlCommand(strSql);
               cmd.Parameters.Add(new SqlParameter("@TaskName",SqlDbType.VarChar,50));
               cmd.Parameters.Add(new SqlParameter("@AssignedRole",SqlDbType.SmallInt));
               cmd.Parameters.Add(new SqlParameter("@AboutAttached",SqlDbType.Char,2));
               cmd.Parameters.Add(new SqlParameter("@Readablefields",SqlDbType.VarChar,800));
               cmd.Parameters.Add(new SqlParameter("@WritableFields",SqlDbType.VarChar,800));
               cmd.Parameters.Add(new SqlParameter("@DueDate",SqlDbType.SmallInt));
               cmd.Parameters.Add(new SqlParameter("@ActivexCode",SqlDbType.VarChar,800));
               cmd.Parameters.Add(new SqlParameter("@PrintedTable",SqlDbType.VarChar,30));
               try
               {
                  cmd.Parameters["@TaskName"].Value=

                         ((TextBox)this.FindControl("TaskName")).Text.Trim();
                  cmd.Parameters["@AssignedRole"].Value=

                       int.Parse(((DropDownList)this.FindControl("roleList")).SelectedValue);
                  cmd.Parameters["@AboutAttached"].Value=

                       ((DropDownList)this.FindControl("attachedList")).SelectedValue.Trim();
                  cmd.Parameters["@Readablefields"].Value=readchkedfields;
                  cmd.Parameters["@WritableFields"].Value=writechkedfields;
                  if(((TextBox)this.FindControl("Due_Date")).Text.Trim()=="")
                  {
                     Label2.Text="任务完成期限不能为空!";
                     return false;
                  }
                  else
                     cmd.Parameters["@DueDate"].Value=

                         int.Parse(((TextBox)this.FindControl("Due_Date")).Text.Trim());

                  //要打印的表格
                  cmd.Parameters["@PrintedTable"].Value=printedtable;     
                  if(! basecode.SQLExeNonQuery_proc(cmd))
                  {
                     Label2.Text=basecode.BaseSqlErrDes;
                     return false;
                  }
               }
               catch(System.FormatException exp)
               {
                  Label2.Text=exp.Message;
                  return false;
               }
               return true;
             
        }
    }

原创粉丝点击