protected void btnSave_Click(object sender, EventArgs e)
    {
        if (FieldValidation() == false)
        {
            return;
        }

        ICustomList CustomManager;

        try
        {
            CustomManager = (ICustomList)ObjectFactory.CreateInstance("BusinessProcess.Administration.BCustomList,BusinessProcess.Administration");
            DataTable DTupdateprior = new DataTable();
            DataSet   DStheXML      = new DataSet();
            DStheXML.ReadXml(MapPath("..\\XMLFiles\\customizelist.xml"));
            DataView theDV = new DataView(DStheXML.Tables["ItemName"]);

            theDV.RowFilter = "TableName='" + ViewState["TableName"] + "' and CategoryId='" + ViewState["CategoryId"] + "' and CountryID='" + ViewState["CCID"] + "' and ModuleId='" + ViewState["ModuleId"] + "'";
            DataTable theDT = theDV.ToTable();
            int       SystemID;
            if (theDT.Rows.Count > 0)
            {
                SystemID = Convert.ToInt32(theDT.Rows[0]["SystemId"]);
            }
            else
            {
                SystemID = Convert.ToInt32(Session["SystemId"]);
            }

            ICustomList PriorManager = (ICustomList)ObjectFactory.CreateInstance("BusinessProcess.Administration.BCustomList, BusinessProcess.Administration");
            if (btnSave.Text == "Save")
            {
                DTupdateprior = PriorManager.GetCustomListUpdatePriortorize(Convert.ToString(ViewState["TableName"]), Convert.ToInt32(ViewState["CategoryId"]), txtSeqNo.Text, SystemID);
                if (DTupdateprior.Rows[0]["UpdateFlag"] != System.DBNull.Value)
                {
                    if (DTupdateprior.Rows[0].IsNull("UpdateFlag") == true)
                    {
                        ViewState["UpdateFlag"] = 0;
                    }
                    else
                    {
                        ViewState["UpdateFlag"] = DTupdateprior.Rows[0]["UpdateFlag"];
                    }
                    if (Convert.ToInt32(ViewState["Updateprior"]) == 2)
                    {
                        IQCareMsgBox.Show("CustomListPriotorize", this);
                        return;
                    }
                }
                string strName;
                strName      = txtName.Text.Trim();
                txtName.Text = strName.Replace("'", "''");
                if (ViewState["CCID"].ToString() == "")
                {
                    ViewState["CCID"] = 0;
                }
                //Extracting SystemID
                string strMultiplier = "";
                if (rdinteger.Checked)
                {
                    strMultiplier = txtmultiplier.Text;
                }

                DataTable RowsAffected = CustomManager.SaveCustomMasterRecord(ViewState["TableName"].ToString(), ViewState["ListName"].ToString(), txtName.Text.Trim(), "", "", Convert.ToInt32(txtSeqNo.Text),
                                                                              Convert.ToInt32(ViewState["CategoryId"]), Convert.ToInt32(Session["AppUserId"]), SystemID, Convert.ToInt32(ViewState["CCID"]), Convert.ToInt32(ViewState["ModuleId"]), strMultiplier);
                if (RowsAffected.Rows.Count <= 0)
                {
                    MsgBuilder theBuilder = new MsgBuilder();
                    theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();

                    if (Convert.ToInt32(ViewState["CategoryId"]) > 0)
                    {
                        theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                    }
                    IQCareMsgBox.Show("CustomMasterExists", theBuilder, this);
                    return;
                }
                else
                {
                    MsgBuilder theBuilder = new MsgBuilder();
                    theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                    //if (Convert.ToInt32(ViewState["CategoryId"]) == 0)
                    //{
                    //    ViewState["CategoryId"] = RowsAffected.Rows[0][0].ToString();
                    //}
                    if (Convert.ToInt32(RowsAffected.Rows[0][0].ToString()) > 0)
                    {
                        theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                    }
                    IQCareMsgBox.Show("CustomMasterSave", theBuilder, this);
                    Clear_Fields();
                }
                //string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}&CCID={6}", "frmAdmin_CustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"], ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString(), ViewState["CCID"].ToString());
                string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}&CCID={6}&ModId={7}", "frmAdmin_CustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"], ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString(), ViewState["CCID"].ToString(), ViewState["ModuleId"].ToString());
                Response.Redirect(Url);
            }
            else
            {
                string strName;
                strName      = txtName.Text.Trim();
                txtName.Text = strName.Replace("'", "''");
                string strMultiplier = "";
                if (rdinteger.Checked)
                {
                    strMultiplier = txtmultiplier.Text;
                }
                DTupdateprior = PriorManager.GetCustomListUpdatePriortorize(Convert.ToString(ViewState["TableName"]), Convert.ToInt32(ViewState["CategoryId"]), txtSeqNo.Text, Convert.ToInt32(Session["SystemId"].ToString()));
                if (DTupdateprior.Rows.Count > 0)
                {
                    if (DTupdateprior.Rows[0]["UpdateFlag"] != System.DBNull.Value)
                    {
                        if (DTupdateprior.Rows[0].IsNull("UpdateFlag") == true)
                        {
                            ViewState["UpdateFlag"] = 0;
                        }
                        else
                        {
                            ViewState["UpdateFlag"] = DTupdateprior.Rows[0]["UpdateFlag"];
                        }
                        if (Convert.ToInt32(ViewState["Updateprior"]) == 2)
                        {
                            IQCareMsgBox.Show("CustomListPriotorize", this);
                            return;
                        }
                    }
                }
                if (ViewState["CCID"].ToString() == "")
                {
                    ViewState["CCID"] = 0;
                }

                if (txtSeqNo.Text != "")
                {
                    CustomManager.UpdateCustomMasterRecord(Convert.ToString(ViewState["TableName"]), Convert.ToInt32(ViewState["Id"]), txtName.Text.Trim(), "", "", Convert.ToInt32(txtSeqNo.Text), Convert.ToInt32(ViewState["CategoryId"]), Convert.ToInt32(ddStatus.SelectedValue), Convert.ToInt32(Session["AppUserId"]), SystemID, Convert.ToInt32(ViewState["CCID"]), Convert.ToInt32(ViewState["ModuleId"]), strMultiplier);
                }
                else
                {
                    CustomManager.UpdateCustomMasterRecord(Convert.ToString(ViewState["TableName"]), Convert.ToInt32(ViewState["Id"]), txtName.Text.Trim(), "", "", 0, Convert.ToInt32(ViewState["CategoryId"]), Convert.ToInt32(ddStatus.SelectedValue), Convert.ToInt32(Session["AppUserId"]), SystemID, Convert.ToInt32(ViewState["CCID"]), Convert.ToInt32(ViewState["ModuleId"]), strMultiplier);
                }


                if (ddStatus.SelectedValue == "1" & txtSeqNo.Text == "")
                {
                    IQCareMsgBox.Show("CustomListInactiveUpdate", this);
                }
                else
                {
                    MsgBuilder theBuilder = new MsgBuilder();
                    theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                    if (Convert.ToInt32(ViewState["CategoryId"]) > 0)
                    {
                        theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                    }
                    IQCareMsgBox.Show("CustomMasterUpdate", theBuilder, this);
                    ViewState["Id"] = 0;
                    Clear_Fields();

                    string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}&CCID={6}&ModId={7}", "frmAdmin_CustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"].ToString(), ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString(), ViewState["CCID"].ToString(), ViewState["ModuleId"].ToString());
                    //string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}&CCID={6}", "frmAdmin_CustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"].ToString(), ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString(), ViewState["CCID"].ToString());
                    //string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}", "frmAdmin_CustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"].ToString(), ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString());
                    Response.Redirect(Url);
                }
            }
        }
        catch (Exception err)
        {
            MsgBuilder theBuilder = new MsgBuilder();
            theBuilder.DataElements["MessageText"] = err.Message.ToString();
            IQCareMsgBox.Show("#C1", theBuilder, this);
            return;
        }
        finally
        {
            CustomManager = null;
        }
    }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (FieldValidation() == false)
            {
                return;
            }

            ICustomList CustomManager;

            try
            {
                CustomManager = (ICustomList)ObjectFactory.CreateInstance("BusinessProcess.Administration.BCustomList,BusinessProcess.Administration");
                DataTable   DTupdateprior = new DataTable();
                ICustomList PriorManager  = (ICustomList)ObjectFactory.CreateInstance("BusinessProcess.Administration.BCustomList, BusinessProcess.Administration");
                if (btnSave.Text == "Save")
                {
                    DTupdateprior = PriorManager.GetCustomListUpdatePriortorize(Convert.ToString(ViewState["TableName"]), Convert.ToInt32(ViewState["CategoryId"]), txtSeqNo.Text, Convert.ToInt32(Session["SystemId"]));
                    if (DTupdateprior.Rows[0]["UpdateFlag"] != System.DBNull.Value)
                    {
                        if (DTupdateprior.Rows[0].IsNull("UpdateFlag") == true)
                        {
                            ViewState["UpdateFlag"] = 1;
                        }
                        else
                        {
                            ViewState["UpdateFlag"] = DTupdateprior.Rows[0]["UpdateFlag"];
                        }

                        if (Convert.ToInt32(ViewState["Updateprior"]) == 2)
                        {
                            IQCareMsgBox.Show("CustomListPriotorize", this);
                            return;
                        }
                    }


                    string strName;
                    strName      = txtName.Text.Trim();
                    txtName.Text = strName.Replace("'", "''");
                    string strCode;
                    strCode      = txtcode.Text.Trim();
                    txtcode.Text = strCode.Replace("'", "''");

                    CustomManager = (ICustomList)ObjectFactory.CreateInstance("BusinessProcess.Administration.BCustomList,BusinessProcess.Administration");
                    DataTable RowsAffected = CustomManager.SaveCustomMasterRecord(ViewState["TableName"].ToString(), ViewState["ListName"].ToString(), txtName.Text.Trim(), txtcode.Text, "", Convert.ToInt32(txtSeqNo.Text), Convert.ToInt32(ViewState["CategoryId"]), Convert.ToInt32(Session["AppUserId"]), Convert.ToInt32(Session["SystemId"]), Convert.ToInt32(ViewState["CCID"]), Convert.ToInt32(ViewState["ModuleId"]), "");
                    if (RowsAffected.Rows.Count <= 0)
                    {
                        MsgBuilder theBuilder = new MsgBuilder();
                        theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();

                        if (Convert.ToInt32(ViewState["CategoryId"]) > 0)
                        {
                            theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                        }
                        IQCareMsgBox.Show("CustomMasterExists", theBuilder, this);
                        return;
                    }
                    else
                    {
                        MsgBuilder theBuilder = new MsgBuilder();
                        theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                        if (Convert.ToInt32(ViewState["CategoryId"]) == 0)
                        {
                            ViewState["CategoryId"] = RowsAffected.Rows[0][0].ToString();
                        }
                        if (Convert.ToInt32(ViewState["CategoryId"]) > 0)
                        {
                            theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                        }
                        IQCareMsgBox.Show("CustomMasterSave", theBuilder, this);
                        Clear_Fields();
                    }
                    //string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}", "frmAdmin_IQCCustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"].ToString(), ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString());
                    string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}&ModId={6}", "frmAdmin_IQCCustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"].ToString(), ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString(), ViewState["ModuleId"].ToString());
                    Response.Redirect(Url);
                }

                else
                {
                    string strName;
                    strName      = txtName.Text.Trim();
                    txtName.Text = strName.Replace("'", "''");
                    string strCode;
                    strCode       = txtcode.Text.Trim();
                    txtcode.Text  = strCode.Replace("'", "''");
                    DTupdateprior = PriorManager.GetCustomListUpdatePriortorize(Convert.ToString(ViewState["TableName"]), Convert.ToInt32(ViewState["CategoryId"]), txtSeqNo.Text, Convert.ToInt32(Session["SystemId"]));
                    if (DTupdateprior.Rows.Count > 0)
                    {
                        if (DTupdateprior.Rows[0]["UpdateFlag"] != System.DBNull.Value)
                        {
                            if (DTupdateprior.Rows[0].IsNull("UpdateFlag") == true)
                            {
                                ViewState["UpdateFlag"] = 0;
                            }
                            else
                            {
                                ViewState["UpdateFlag"] = DTupdateprior.Rows[0]["UpdateFlag"];
                            }

                            if (Convert.ToInt32(ViewState["Updateprior"]) == 2)
                            {
                                IQCareMsgBox.Show("CustomListPriotorize", this);
                                return;
                            }
                        }
                    }
                    if (txtSeqNo.Text != "")
                    {
                        CustomManager.UpdateCustomMasterRecord(ViewState["TableName"].ToString(), Convert.ToInt32(ViewState["Id"]), txtName.Text.Trim(), txtcode.Text.Trim(), "", Convert.ToInt32(txtSeqNo.Text), Convert.ToInt32(ViewState["CategoryId"]), Convert.ToInt32(ddStatus.SelectedValue), Convert.ToInt32(Session["AppUserId"]), Convert.ToInt32(Session["SystemId"]), Convert.ToInt32(ViewState["CCID"]), Convert.ToInt32(ViewState["ModuleId"]), "");
                    }
                    else
                    {
                        CustomManager.UpdateCustomMasterRecord(ViewState["TableName"].ToString(), Convert.ToInt32(ViewState["Id"]), txtName.Text.Trim(), txtcode.Text.Trim(), "", 0, Convert.ToInt32(ViewState["CategoryId"]), Convert.ToInt32(ddStatus.SelectedValue), Convert.ToInt32(Session["AppUserId"]), Convert.ToInt32(Session["SystemId"]), Convert.ToInt32(ViewState["CCID"]), Convert.ToInt32(ViewState["ModuleId"]), "");
                    }
                    if (ddStatus.SelectedValue == "1" & txtSeqNo.Text == "")
                    {
                        IQCareMsgBox.Show("CustomListInactiveUpdate", this);
                    }
                    else
                    {
                        MsgBuilder theBuilder = new MsgBuilder();
                        theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                        if (Convert.ToInt32(ViewState["CategoryId"]) > 0)
                        {
                            theBuilder.DataElements["Name"] = ViewState["ListName"].ToString();
                        }
                        IQCareMsgBox.Show("CustomMasterUpdate", theBuilder, this);

                        ViewState["Id"] = 0;
                        //Clear_Fields();
                        //string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}", "frmAdmin_IQCCustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"].ToString(), ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString());
                        string Url = string.Format("{0}?TableName={1}&CategoryId={2}&LstName={3}&Fid={4}&Upd={5}&ModId={6}", "frmAdmin_IQCCustomList.aspx", ViewState["TableName"].ToString(), ViewState["CategoryId"].ToString(), ViewState["ListName"].ToString(), ViewState["FID"].ToString(), ViewState["Update"].ToString(), ViewState["ModuleId"].ToString());
                        Response.Redirect(Url);
                    }
                }
            }

            catch (Exception err)
            {
                MsgBuilder theBuilder = new MsgBuilder();
                theBuilder.DataElements["MessageText"] = err.Message.ToString();
                IQCareMsgBox.Show("#C1", theBuilder, this);
                return;
            }
            finally
            {
                CustomManager = null;
            }
        }