protected void btnAddSalesType_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (hdnIsValidSearch.Value == "Y" && !string.IsNullOrWhiteSpace(txtSalesTypeGroup.Text))
                {
                    string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
                    string selectdSalesTypeGroupCode = txtSalesTypeGroup.Text.Split('-')[0].ToString().Trim();
                    string salesTypeCode;

                    List <string> salesTypeCodesToAdd = new List <string>();
                    CheckBox      cbAddSalesType;

                    foreach (GridViewRow gridrow in gvGroupOut.Rows)
                    {
                        cbAddSalesType = (CheckBox)gridrow.FindControl("cbAddSalesType");
                        if (cbAddSalesType.Checked)
                        {
                            salesTypeCode = (gridrow.FindControl("lblSalesTypeCode") as Label).Text;
                            salesTypeCodesToAdd.Add(salesTypeCode);
                        }
                    }

                    if (salesTypeCodesToAdd.Count > 0)
                    {
                        salesTypeGroupingBL = new SalesTypeGroupingBL();
                        DataSet salesTypeGroupInOutData = salesTypeGroupingBL.AddSalesTypeToGroup(selectdSalesTypeGroupCode, salesTypeCodesToAdd.ToArray(), userCode, out errorId);
                        salesTypeGroupingBL = null;

                        BindGrids(salesTypeGroupInOutData);

                        txtGroupOutBox.Text = string.Empty;
                        txtGroupInBox.Text  = string.Empty;

                        hdnisItemSelectedIn.Value  = "N";
                        hdnisItemSelectedOut.Value = "N";
                    }
                    else
                    {
                        msgView.SetMessage("Please select a sales type from 'Out of the Group' list",
                                           MessageType.Warning, PositionType.Auto);
                    }
                }
                else
                {
                    msgView.SetMessage("Please select a sales type group from searched list",
                                       MessageType.Warning, PositionType.Auto);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in adding sales type to group.", ex.Message);
            }
        }
        private void SalesTypeGroupSelected()
        {
            hdnIsValidSearch.Value = "Y";
            salesTypeGroupingBL    = new SalesTypeGroupingBL();
            DataSet salesTypeGroupInOutData = salesTypeGroupingBL.GetSalesTypeGroupInOutData(txtSalesTypeGroup.Text.Split('-')[0].ToString().Trim(), out errorId);

            salesTypeGroupingBL = null;

            BindGrids(salesTypeGroupInOutData);
            gvGroupIn.DataSource = salesTypeGroupInOutData.Tables[0];
            gvGroupIn.DataBind();

            txtGroupInBox.Text  = string.Empty;
            txtGroupOutBox.Text = string.Empty;
            UserAuthorization();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());

                salesTypeGroupingBL = new SalesTypeGroupingBL();
                DataSet salesTypeGroupInOutData = salesTypeGroupingBL.InsertSalesTypeGroup(txtGroupCode.Text.Trim(), txtGroupDesc.Text.Trim(), userCode, out errorId);
                salesTypeGroupingBL = null;

                if (errorId == 1)
                {
                    msgView.SetMessage("The sales type group code already exists",
                                       MessageType.Warning, PositionType.Auto);
                    mpeInsertGroup.Show();
                    txtGroupCode.Focus();
                }

                else
                {
                    BindGrids(salesTypeGroupInOutData);
                    if (salesTypeGroupInOutData.Tables.Count == 3)
                    {
                        Session["FuzzySearchPriceGroupListTypeP"] = salesTypeGroupInOutData.Tables[2];
                    }
                    txtSalesTypeGroup.Text = txtGroupCode.Text.Trim() + " - " + txtGroupDesc.Text.Trim();
                    hdnIsValidSearch.Value = "Y";
                    txtGroupCode.Text      = string.Empty;
                    txtGroupDesc.Text      = string.Empty;
                    txtGroupOutBox.Text    = string.Empty;
                    txtGroupInBox.Text     = string.Empty;
                    mpeInsertGroup.Hide();
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in adding a new configuration group.", ex.Message);
            }
        }