protected void btnSave_Click(object sender, EventArgs e)
        {
            Category dataObj = new Category();
            dataObj.CategoryName = this.txtCatName.Text;
            dataObj.Description = this.txtDescription.Text;
            /*dataObj.CategoryID = -1;
            dataObj.CompanyName = this.txtCompanyName.Text;
            dataObj.Contactname = this.txtContactName.Text;
            dataObj.ContactTitle = this.txtTitle.Text;
            dataObj.Address = this.txtAddress.Text;
            dataObj.City = this.txtCity.Text;
            dataObj.Region = this.txtRegion.Text;
            dataObj.Postalcode = this.txtPostalCode.Text;
            dataObj.Country = this.txtCountry.Text;
            dataObj.Phone = this.txtPhone.Text;
            dataObj.Fax = this.txtFax.Text;*/

            try
            {

                int check = dataObj.isValid();

                if (check < 0)
                {
                    //MessageBox.Show(newEmp.getErrorMessage(check));
                    this.script.Text = "<script>alert(\""+dataObj.getErrorMessage(check)+"\");</script>";
                    return;
                }
                else
                {
                    if (this.newEmpMode == true)
                        this.dataModel.insertNewRow(dataObj);
                    else
                    {
                        dataObj.CategoryID = this.suppID;
                        this.dataModel.updateRow(dataObj);
                    }

                    //Server.Transfer("Categorys.aspx", true);
                }
            }
            catch (Exception ex)
            {
                Session["current_error"] = ex.Message;
                Response.Redirect("serverError.aspx");
            }

            Response.Redirect("Categories.aspx");
        }
Exemple #2
0
        public string Update(string id, DataModel.Category data)
        {
            connection = new SqlConnection(connectionString);
            string sql = "UPDATE [category] SET [category] = @category WHERE [idcategory] = @idcategory";

            try
            {
                connection.Execute(sql, new { idcategory = id, category = data.Name });
                return("Success");
            }
            catch (Exception err)
            {
                error = err.ToString();
                return(error);
            }
        }
Exemple #3
0
        public string Add(DataModel.Category data)
        {
            connection = new SqlConnection(connectionString);
            string sql = "INSERT INTO [category] ([idcategory],[category]) VALUES (@idcategory , @category)";

            try
            {
                connection.Execute(sql, new { idcategory = data.Id, category = data.Name });
                return("Success");
            }
            catch (Exception err)
            {
                error = err.ToString();
                return(error);
            }
        }