Esempio n. 1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                Inv_ProductGroup groupObj = new Inv_ProductGroup();
                groupObj.GroupName = txtGroupName.Text;

                //if (groupBll.GetGroupByName(groupObj.GroupName) != null)
                //{
                //    lblMessage.Text = "Data Already in the List";
                //    lblMessage.ForeColor = System.Drawing.Color.Red;
                //    txtGroupName.Text = "";
                //    return;
                //}

                int Groupcount = (from grp in _context.Inv_ProductGroup
                                  where grp.GroupName == groupObj.GroupName
                                  select grp.GroupId).Count();
                if (Groupcount == 0)
                {
                    if (btnSubmit.Text == "Submit")
                    {
                        //groupObj.EditUser = Guid.Parse("a376708d-757f-4777-bd05-bfc89b6971ce");
                        groupObj.EditUser = ((SessionUser)Session["SessionUser"]).UserId;

                        int result = groupBll.InsertGroup(groupObj);
                        if (result == 1)
                        {
                            // lblMessage.Text = "Data Saved Successfully";
                            // lblMessage.ForeColor = System.Drawing.Color.Green;
                            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Saved Successfully')", true);
                        }
                        else
                        {
                            // lblMessage.Text = "Data Saving Failure";
                            //  lblMessage.ForeColor = System.Drawing.Color.Red;
                            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Saving Failure')", true);
                        }
                    }
                    else
                    {
                        int groupId = Convert.ToInt32(hdfProductGroupID.Value);

                        int result = groupBll.UpdateGroup(groupObj, groupId);
                        if (result == 1)
                        {
                            //  lblMessage.Text = "Data Updated Successfully";
                            //  lblMessage.ForeColor = System.Drawing.Color.Green;
                            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Updated Successfully')", true);
                        }
                        else
                        {
                            // lblMessage.Text = "Data Updating failure";
                            //  lblMessage.ForeColor = System.Drawing.Color.Red;
                            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Updating failure')", true);
                        }
                    }
                    GetAllProductGroup();
                    txtGroupName.Text = "";
                    txtGroupName.Focus();
                    btnSubmit.Text = "Submit";
                }
                else
                {
                    //lblMessage.Text = "Data Already Exist";
                    // lblMessage.ForeColor = System.Drawing.Color.Red;
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Already Exist')", true);
                    txtGroupName.Text = "";
                    txtGroupName.Focus();
                    btnSubmit.Text = "Submit";
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('" + ex.Message + "')", true);
            }
        }