Exemplo n.º 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            Brand objBrand = new Brand();
            objBrand.BrandId = Int32.Parse(hdnBrandId.Value);
            objBrand.GetBrandByID();

            objBrand.BrandName = txtBrandName.Text.Trim();

            DataSet dsCatg = objBrand.DsCategories.Copy();

            DataView dvCategories = dsCatg.Tables[0].DefaultView;
            dvCategories.Sort = "CategoryId";

            for (int i = 0; i < cblCategoryType.Items.Count; i++)
            {
                int found = -1;
                found = dvCategories.Find(cblCategoryType.Items[i].Value);

                if (cblCategoryType.Items[i].Selected && found == -1)
                {
                    DataRow newRow = dvCategories.Table.NewRow();
                    newRow["CategoryId"] = Convert.ToInt32(cblCategoryType.Items[i].Value.ToString());
                    newRow["CategoryType"] = cblCategoryType.Items[i].Text;
                    newRow.EndEdit();
                    dvCategories.Table.Rows.Add(newRow);
                }
                else if (cblCategoryType.Items[i].Selected == false && found != -1)
                {
                    dvCategories.Delete(found);
                }
            }

            objBrand.DsCategories = null;
            objBrand.DsCategories = dsCatg;

            if ( objBrand.Save())
            {
                lblError.Visible = true;
                lblError.Text = Constant.MSG_Save_SavedSeccessfully;
                hdnBrandId.Value = objBrand.BrandId.ToString();
            }
            else
            {
                lblError.Visible = true;
                lblError.Text = Constant.MSG_Save_NotSavedSeccessfully;
            }
        }
        catch (Exception ex)
        {
            ex.Data.Add("UILayerException", this.GetType().ToString() + Constant.Error_Seperator + "protected void btnSave_Click(object sender, EventArgs e)");
            if (Master.LoggedUser != null && Master.LoggedUser.UserName != null && Master.LoggedUser.UserName != string.Empty)
                Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, Master.LoggedUser.UserName), false);
            else
                Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, "Annonimous"), false);

        }
    }