Beispiel #1
0
        /// <summary>
        /// To save or edit details to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ADDButton_Click(object sender, EventArgs e)
        {
            string message      = string.Empty;
            string AlertMessage = string.Empty;


            WorkFlowBLL  WorkFlowBLLOBJ = new WorkFlowBLL();
            WorkFlowList WorkFlowList   = new WorkFlowList();
            int          level          = 0;
            int          count;
            int          sameLavel         = 0;
            string       projectID         = Session["PROJECT_ID"].ToString();
            string       testWorkflowDefID = ViewState["WorkFlowDefID"].ToString();
            string       WorkflowDefID     = ViewState["WorkFlowDefID"].ToString();

            WorkFlowList = WorkFlowBLLOBJ.GetApprover(projectID, WorkflowDefID);
            if (WorkFlowList.Count == 0)
            {
                level = level + 1;
                if (level == (Convert.ToInt32(ApproverLevelDropDownList.SelectedItem.Value.ToString())))
                {
                    sameLavel = 0;
                }
                else
                {
                    sameLavel = 1;
                }
            }
            else
            {
                for (int i = 0; i < WorkFlowList.Count; i++)
                {
                    if (WorkApproverIDTextBox.Text != "0")
                    {
                        level = (WorkFlowList[i].LEVEL);
                        if (level == (Convert.ToInt32(ApproverLevelDropDownList.SelectedItem.Value.ToString())))
                        {
                            sameLavel = 0;
                        }
                        else
                        {
                            sameLavel = 1;
                            break;
                        }
                    }
                    else
                    {
                        level = (WorkFlowList[i].LEVEL) + 1;
                        if (level == (Convert.ToInt32(ApproverLevelDropDownList.SelectedItem.Value.ToString())))
                        {
                            sameLavel = 0;
                        }
                        else
                        {
                            sameLavel = 1;
                        }
                    }
                }
            }

            if (WorkApproverIDTextBox.Text != "0")
            {
                #region for update
                if (sameLavel == 0)
                {
                    string     uID         = Session["USER_ID"].ToString();
                    string     pID         = Session["PROJECT_ID"].ToString();
                    WorkFlowBO objWorkFlow = new WorkFlowBO();

                    objWorkFlow.ApprovalID     = Convert.ToInt32(ApproverRoleNameDropDownList.SelectedItem.Value.ToString());
                    objWorkFlow.ApproverUserID = Convert.ToInt32(ApproverNameDropDownList.SelectedItem.Value.ToString());
                    objWorkFlow.LEVEL          = Convert.ToInt32(ApproverLevelDropDownList.SelectedItem.Value.ToString());
                    objWorkFlow.UserID         = Convert.ToInt32(uID);
                    objWorkFlow.ProjectID      = Convert.ToInt32(pID);
                    objWorkFlow.WorkFlowDefID  = Convert.ToInt32(WorkDefinationTextBox.Text.ToString());
                    objWorkFlow.WorkApprovalID = Convert.ToInt32(ViewState["WorkApprovalID"]);

                    count = WorkFlowBLLOBJ.EditAPPROVALADD(objWorkFlow);
                    if (count == 1)
                    {
                        message      = "Approver or Level Already Exists";
                        AlertMessage = "alert('" + message + "');";
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
                        BindGrid(true, true);
                        ADDButton.Visible          = true;
                        UpDateButton.Visible       = false;
                        CancelButton.Visible       = false;
                        WorkApproverIDTextBox.Text = "0";
                        WorkDefinationTextBox.Text = "0";
                        ListItem lstItem = ApproverNameDropDownList.Items[0];
                        ApproverNameDropDownList.Items.Clear();
                        ApproverNameDropDownList.Items.Insert(0, lstItem);
                        ApproverLevelDropDownList.Enabled = true;
                    }
                    else if (count == -1)
                    {
                        message      = "Approver updated successfully";
                        AlertMessage = "alert('" + message + "');";
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
                        BindGrid(true, true);
                        ADDButton.Visible          = true;
                        UpDateButton.Visible       = false;
                        CancelButton.Visible       = false;
                        WorkApproverIDTextBox.Text = "0";
                        WorkDefinationTextBox.Text = "0";
                        ListItem lstItem = ApproverNameDropDownList.Items[0];
                        ApproverNameDropDownList.Items.Clear();
                        ApproverNameDropDownList.Items.Insert(0, lstItem);
                        ApproverLevelDropDownList.Enabled = true;
                    }
                }
                else
                {
                    message      = "Approver or Level Already Exists";
                    AlertMessage = "alert('" + message + "');";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
                    BindGrid(true, true);
                    ADDButton.Visible          = true;
                    UpDateButton.Visible       = false;
                    CancelButton.Visible       = false;
                    WorkApproverIDTextBox.Text = "0";
                    WorkDefinationTextBox.Text = "0";
                    ListItem lstItem = ApproverNameDropDownList.Items[0];
                    ApproverNameDropDownList.Items.Clear();
                    ApproverNameDropDownList.Items.Insert(0, lstItem);
                    ApproverLevelDropDownList.Enabled = true;
                    //getAllRole();
                }
                getAllRole();
                getLevel();
                #endregion
            }
            else
            {
                #region For Save
                try
                {
                    if (sameLavel == 0)
                    {
                        string     uID         = Session["USER_ID"].ToString();
                        string     pID         = Session["PROJECT_ID"].ToString();
                        WorkFlowBO objWorkFlow = new WorkFlowBO();

                        objWorkFlow.ApprovalID     = Convert.ToInt32(ApproverRoleNameDropDownList.SelectedItem.Value.ToString());
                        objWorkFlow.ApproverUserID = Convert.ToInt32(ApproverNameDropDownList.SelectedItem.Value.ToString());
                        objWorkFlow.LEVEL          = Convert.ToInt32(ApproverLevelDropDownList.SelectedItem.Value.ToString());
                        objWorkFlow.UserID         = Convert.ToInt32(uID);
                        objWorkFlow.ProjectID      = Convert.ToInt32(pID);
                        objWorkFlow.WorkFlowDefID  = Convert.ToInt32(ViewState["WorkFlowDefID"]);

                        count = WorkFlowBLLOBJ.InsertAPPROVALADD(objWorkFlow);
                        if (count == 1)
                        {
                            message      = "Approver or Level Already Exists";
                            AlertMessage = "alert('" + message + "');";
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
                            BindGrid(true, true);
                            getAllRole();
                            getLevel();
                            ListItem lstItem = ApproverNameDropDownList.Items[0];
                            ApproverNameDropDownList.Items.Clear();
                            ApproverNameDropDownList.Items.Insert(0, lstItem);
                        }
                        else if (count == -1)
                        {
                            message      = "Approver Added successfully";
                            AlertMessage = "alert('" + message + "');";
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
                            BindGrid(true, true);
                            getAllRole();
                            getLevel();
                            ListItem lstItem = ApproverNameDropDownList.Items[0];
                            ApproverNameDropDownList.Items.Clear();
                            ApproverNameDropDownList.Items.Insert(0, lstItem);
                        }
                    }
                    else
                    {
                        message      = " Approvers are Not Defined for Previous Level(s) ";
                        AlertMessage = "alert('" + message + "');";
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
                        BindGrid(true, true);
                        getAllRole();
                        getLevel();
                        ListItem lstItem = ApproverNameDropDownList.Items[0];
                        ApproverNameDropDownList.Items.Clear();
                        ApproverNameDropDownList.Items.Insert(0, lstItem);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                finally
                {
                    WorkFlowBLLOBJ = null;
                }
                #endregion
            }
        }