Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string sWorkflowTemplagteName = this.txtWorkflowTemplate.Text.Trim();
            string sWorkflowType          = this.ddlWorkflowType.SelectedValue;
            bool   bEnabled           = this.chkEnabled.Checked;
            string sDesc              = this.txtDesc.Text.Trim();
            string sCalcDueDateMethod = this.ddlCalcDueDateMethod.SelectedValue;
            bool   bDefault           = this.chkDefault.Checked;

            #region get stage data

            string sSequences              = this.hdnSequences.Text;
            string sStageTempIDs           = this.hdnStageTemplateIDs.Text;
            string sWflStageIDs            = this.hdnWflStageIDs.Text;
            string sStageNames             = this.hdnStageNames.Text; // Open$Submit$Approve
            string sEnableds               = this.hdnEnableds.Text;
            string sDaysFromEstCloseDates  = this.hdnDaysFromEstCloseDates.Text;
            string sDaysAfterCreationDates = this.hdnDaysAfterCreationDates.Text;
            string sCalculationMethods     = this.hdnCalculationMethod.Text;

            #endregion

            Template_Workflow WorkflowTemplateManager = new Template_Workflow();

            #region build stage list

            DataTable StageList = WorkflowTemplateManager.GetWflStageList(" and (1=0)");
            StageList.Columns.Add("OldWflStageId", Type.GetType("System.Int32"));

            if (sSequences != string.Empty)
            {
                string[] SequenceArray              = sSequences.Split(',');
                string[] StageTempIDArray           = sStageTempIDs.Split(',');
                string[] WflStageIDArray            = sWflStageIDs.Split(',');
                string[] StageNameArray             = sStageNames.Split(',');
                string[] EnabledArray               = sEnableds.Split(',');
                string[] DaysFromEstCloseDateArray  = sDaysFromEstCloseDates.Split(',');
                string[] DaysAfterCreationDateArray = sDaysAfterCreationDates.Split(',');
                string[] CalculationMethodArray     = sCalculationMethods.Split(',');

                for (int i = 0; i < SequenceArray.Length; i++)
                {
                    string sSequence              = SequenceArray[i];
                    string sStageTempID           = StageTempIDArray[i];
                    string sWflStageID            = WflStageIDArray[i];
                    string sStageNameBlock        = StageNameArray[i];
                    string sEnabled               = EnabledArray[i];
                    string sDaysFromEstCloseDate  = DaysFromEstCloseDateArray[i];
                    string sDaysAfterCreationDate = DaysAfterCreationDateArray[i];
                    string sCalculationMethod     = CalculationMethodArray[i];

                    #region format StageName

                    string sStageName = sStageNameBlock.Replace("[$", string.Empty);
                    sStageName = sStageName.Replace("$]", string.Empty);

                    #endregion

                    #region add rows

                    DataRow StageRow = StageList.NewRow();
                    StageRow["WflStageId"]     = 0;
                    StageRow["WflTemplId"]     = 0;
                    StageRow["OldWflStageId"]  = sWflStageID;
                    StageRow["Name"]           = sStageName;
                    StageRow["SequenceNumber"] = Convert.ToInt16(sSequence);
                    StageRow["Enabled"]        = Convert.ToBoolean(sEnabled);
                    if (sCalculationMethod != "" && sCalculationMethod != "0")
                    {
                        StageRow["CalculationMethod"] = sCalculationMethod;
                    }
                    //else
                    //{
                    //if (sCalcDueDateMethod == "Est Close Date")
                    //{
                    //    StageRow["CalculationMethod"] = 1;
                    //}
                    //else if (sCalcDueDateMethod == "Creation Date")
                    //{
                    //    StageRow["CalculationMethod"] = 2;
                    //}
                    //else {

                    //    StageRow["CalculationMethod"] = 3;
                    //}
                    //}


                    //if (sCalcDueDateMethod == "Est Close Date")
                    //{
                    if (sDaysFromEstCloseDate == "null")
                    {
                        StageRow["DaysFromEstClose"] = DBNull.Value;
                    }
                    else
                    {
                        StageRow["DaysFromEstClose"] = Convert.ToInt16(sDaysFromEstCloseDate);
                    }

                    //StageRow["DaysFromCreation"] = DBNull.Value;

                    //}
                    //else
                    //{
                    //StageRow["DaysFromEstClose"] = DBNull.Value;

                    if (sDaysAfterCreationDate == "null")
                    {
                        StageRow["DaysFromCreation"] = DBNull.Value;
                    }
                    else
                    {
                        StageRow["DaysFromCreation"] = Convert.ToInt16(sDaysAfterCreationDate);
                    }

                    //}

                    StageRow["TemplStageId"] = sStageTempID;

                    StageList.Rows.Add(StageRow);

                    #endregion
                }
            }

            #endregion

            // insert
            //WorkflowTemplateManager.InsertWorkflowTemplate(sWorkflowTemplagteName, bEnabled, sDesc, sWorkflowType, bDefault, sCalcDueDateMethod, StageList);
            WorkflowTemplateManager.CloneWorkflowTemplate(sWorkflowTemplagteName, bEnabled, sDesc, sWorkflowType, bDefault, sCalcDueDateMethod, StageList);

            // success
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Success", "$('#divContainer').hide();alert('Clone workflow template successfully.');window.parent.location.href='WorkflowTemplateList.aspx';", true);
        }