public int AddCategory(CategoryDetails categoryDetails) { try { DALComponent objDALCategory = new DALComponent(); objDALCategory.SetParameters("@categoryId", SqlDbType.Int, 4, categoryDetails.CategoryID); objDALCategory.SetParameters("@categoryName", SqlDbType.VarChar, 50, categoryDetails.CategoryName); objDALCategory.SetParameters("@categoryDesc", SqlDbType.VarChar, 300, categoryDetails.CategoryDescription); objDALCategory.SetParameters("@idvalue", SqlDbType.Int, true); objDALCategory.SqlCommandText = "[CreateCategory]"; int x = objDALCategory.CreateRecord(); object y = objDALCategory.GetParameters("@idvalue"); if (categoryDetails.CategoryID != 0) return categoryDetails.CategoryID; else return Int32.Parse(y.ToString()); } catch (SqlException sqlEx) { throw new ApplicationException("Data error=" + sqlEx.Message.ToString()); } catch (Exception ex) { throw new ApplicationException("Error=" + ex.Message.ToString()); } }
protected void btnSave_Click(object sender, EventArgs e) { int r = 0; ServeAtDoorstepData.CategoryDetails objCategory = new CategoryDetails(); objCategory.CategoryID = 0; objCategory.CategoryName = txtcategory.Text.ToString().Trim(); objCategory.CategoryDescription =txtcategoryDesc.Text.Trim(); objService = new ServeAtDoorstepService(); DataTable dt = objService.AvailableCategory(txtcategory.Text.ToString().Trim()); if (dt.Rows.Count == 0 && txtcategory.Text.ToString().Trim() != "") r = objService.AddCategory(objCategory); txtcategory.Text = ""; LoadCategory(); }
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e) { // Get the DataKey value associated with current Item Index. int catId = (int)DataList1.DataKeys[(int)e.Item.ItemIndex]; // Get updated value entered by user in textbox control for // Name field. TextBox txtId; txtId = (TextBox)e.Item.FindControl("txtId"); TextBox txtCName; txtCName = (TextBox)e.Item.FindControl("txtCName"); TextBox txtCDesc; txtCDesc = (TextBox)e.Item.FindControl("txtCDesc"); // string variable to store the connection string // retrieved from the connectionStrings section of web.config ServeAtDoorstepData.CategoryDetails objCategory = new CategoryDetails(); objCategory.CategoryID=Convert.ToInt32(txtId.Text.ToString().Trim()); objCategory.CategoryName=txtCName.Text.ToString().Trim(); objCategory.CategoryDescription = txtCDesc.Text.Trim(); objService = new ServeAtDoorstepService(); int r = objService.AddCategory(objCategory); // reset the DataList mode back to its initial state DataList1.EditItemIndex = -1; LoadCategory(); }