protected void modalDescription_Changed(object sender, EventArgs e)
        {
            string errorMsg = "Description already used. ";
            if (modalTxtBoxDescription.Text.Trim() != "")
            {
                JobFlow jobflow = new JobFlow();
                jobflow = jobflow.GetJobFlowByDescription(modalTxtBoxDescription.Text.Trim());

                if (jobflow != null)
                {
                    if (modalLabelJobFlowId.Text.Trim() == "")
                    {
                        modalLabelError.Text += errorMsg;
                        modalLabelError.Visible = true;
                    }
                    else
                    {
                        JobFlow j = jobflow.GetJobFlow(Convert.ToInt32(modalLabelJobFlowId.Text));
                        if (j.Description.Trim().Equals(modalTxtBoxDescription.Text.Trim(), StringComparison.OrdinalIgnoreCase) == true)
                        {
                            modalLabelError.Text += errorMsg;
                            modalLabelError.Visible = true;
                        }
                        else
                        {
                            modalLabelError.Text = modalLabelError.Text.Replace(errorMsg, "").Trim();
                        }
                    }
                }
                else
                {
                    modalLabelError.Text = modalLabelError.Text.Replace(errorMsg, "").Trim();
                }
            }
            else
            {
                modalLabelError.Text = modalLabelError.Text.Replace(errorMsg, "").Trim();
            }
            if (modalLabelError.Text.Trim().Length == 0)
            {
                modalLabelError.Visible = false;
            }
            this.programmaticModalPopup.Show();
        }
        protected void modalBtnSubmit_Command(object sender, CommandEventArgs e)
        {
            if (gridViewModal.Rows.Count == 0 ||(modalLabelJobFlowId.Text.Trim() != "" && IsCheckBoxEmpty()))
            {
                modalLabelError.Visible = true;
                modalLabelError.Text += " Please add atleast one department.";
                this.programmaticModalPopup.Show();
            }
            else if (modalLabelError.Visible == true)
                this.programmaticModalPopup.Show();
            else
            {
                JobFlow jobflow = new JobFlow();

                if (modalLabelJobFlowId.Text.Trim() != "")
                {
                    jobflow = jobflow.GetJobFlow(Convert.ToInt32(modalLabelJobFlowId.Text));
                }
                jobflow.Description = modalTxtBoxDescription.Text.Trim();
                jobflow.Acronym = modalTxtBoxAcronym.Text.Trim();
                jobflow.Position = modalTxtBoxPosition.Text.Trim() == "" ? 0 : Convert.ToInt32(modalTxtBoxPosition.Text);

                if (modalLabelJobFlowId.Text.Trim() == "")
                {
                    jobflow.Insert(jobflow);
                    jobflow = jobflow.GetJobFlowByDescription(jobflow.Description);
                }
                else
                {
                    jobflow.Update(jobflow);
                }

                for (int i = 0; i < gridViewModal.Rows.Count; i++)
                {
                    JobTypeFlow jobTypeFlow = new JobTypeFlow();
                    CheckBox cb = (CheckBox)gridViewModal.Rows[i].FindControl("modalChkJobType");
                    Label labelJobTypeId = (Label)gridViewModal.Rows[i].FindControl("modalLabelJobTypeId");
                    Label labelDeptId = (Label)gridViewModal.Rows[i].FindControl("modalLabelDepartmentId");
                    TextBox txtBoxPosition = (TextBox)gridViewModal.Rows[i].FindControl("modalInnerTxtBoxPostion");

                    int jobtypeid = Convert.ToInt32(labelJobTypeId.Text);
                    int? deptid = Convert.ToInt32(labelDeptId.Text.Trim() == "" ? "0" : labelDeptId.Text);
                    if(deptid == 0)
                        deptid = null;
                    jobTypeFlow = jobTypeFlow.GetJobTypeFlow(jobflow.Id,jobtypeid,deptid);
                    if (cb.Checked)
                    {
                        if (jobTypeFlow == null)
                        {
                            jobTypeFlow = new JobTypeFlow();
                            jobTypeFlow.JobFlowId = jobflow.Id;
                            jobTypeFlow.JobTypeId = jobtypeid;
                            jobTypeFlow.DepartmentId = deptid;
                            jobTypeFlow.Position = txtBoxPosition.Text.Trim() == "" ? 0 : Convert.ToInt32(txtBoxPosition.Text.Trim());
                            jobTypeFlow.Insert(jobTypeFlow);
                        }
                        else
                        {
                            jobTypeFlow.Position = txtBoxPosition.Text.Trim() == "" ? 0 : Convert.ToInt32(txtBoxPosition.Text.Trim());
                            jobTypeFlow.Update(jobTypeFlow);
                        }
                    }
                    else
                    {
                        if (jobTypeFlow != null)
                        {
                            jobTypeFlow.Delete(jobTypeFlow.Id);
                        }
                    }
                }
                if(IsCheckBoxEmpty())
                {
                    jobflow.Delete(jobflow.Id);
                }
                Session["JobFlows"] = null;
                InitializeMainGrid();
            }
        }