protected void grdItemMaster_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("ADD")) { DropDownList ddlNewCanteenName = (DropDownList)grdItemMaster.FooterRow.FindControl("ddlNewCanteenName"); DropDownList ddlNewCategoryGroupCode = (DropDownList)grdItemMaster.FooterRow.FindControl("ddlNewCategoryGroupCode"); DropDownList ddlNewCategoryItemCode = (DropDownList)grdItemMaster.FooterRow.FindControl("ddlNewCategoryItemCode"); TextBox txtNewItemName = (TextBox)grdItemMaster.FooterRow.FindControl("txtNewItemName"); TextBox txtNewItemEmployeeRate = (TextBox)grdItemMaster.FooterRow.FindControl("txtNewItemEmployeeRate"); CheckBox ChStatusNew = (CheckBox)grdItemMaster.FooterRow.FindControl("ChStatusNew"); if (IsValid) { //errNumber = -1; try { objBusinessClass = new BusinessLayer.BusinessClass(); objML_ItemMaster = new ML_ItemMaster(); objML_ItemMaster.CanteenCode = Convert.ToInt32(ML_Common.clean(ddlNewCanteenName.SelectedValue)); objML_ItemMaster.CategoryGroupCode = Convert.ToInt32(ML_Common.clean(ddlNewCategoryGroupCode.SelectedValue)); objML_ItemMaster.ItemCategoryCode = Convert.ToInt32(ML_Common.clean(ddlNewCategoryItemCode.SelectedValue)); objML_ItemMaster.ItemName = ML_Common.clean(txtNewItemName.Text); objML_ItemMaster.ItemEmployeeRate = Convert.ToDecimal(ML_Common.clean(txtNewItemEmployeeRate.Text)); if (ChStatusNew.Checked) { objML_ItemMaster.ItemActive = 1; } else { objML_ItemMaster.ItemActive = 0; } int obhReturn = objBusinessClass.AddItemMaster(objML_ItemMaster); if (obhReturn == 1) { lblMsg.Visible = true; lblMsg.Text = "Record Saved Successfully"; FillGrid(); } else if (obhReturn == 2) { lblMsg.Text = "Record Already Exists!"; lblMsg.Visible = true; } } catch (SqlException sqlExc) { // LogManager.LogManager.WriteErrorLog(sqlExc); SqlException sqlEt = sqlExc; return; } catch (Exception ex) { Exception exc = ex;// Exception exc=ex;// LogManager.LogManager.WriteErrorLog(ex); } } } }
protected void grdItemMaster_RowUpdating(object sender, GridViewUpdateEventArgs e) { DropDownList ddlCanteenName = (DropDownList)grdItemMaster.Rows[e.RowIndex].FindControl("ddlCanteenName"); DropDownList ddlCategoryGroupCode = (DropDownList)grdItemMaster.Rows[e.RowIndex].FindControl("ddlCategoryGroupCode"); DropDownList ddlCategoryItemCode = (DropDownList)grdItemMaster.Rows[e.RowIndex].FindControl("ddlCategoryItemCode"); TextBox txtItemNameEdit = (TextBox)grdItemMaster.Rows[e.RowIndex].FindControl("txtItemNameEdit"); TextBox txtItemEmployeeRateEdit = (TextBox)grdItemMaster.Rows[e.RowIndex].FindControl("txtItemEmployeeRateEdit"); CheckBox ChStatusEdit = (CheckBox)grdItemMaster.Rows[e.RowIndex].FindControl("ChStatusEdit"); if (IsValid) { //errNumber = -1; BusinessClass objBusinessClass = new BusinessLayer.BusinessClass(); int lngId = ML_Common.string2int(grdItemMaster.DataKeys[e.RowIndex].Values[0].ToString()); ML_ItemMaster objML_ItemMaster = objBusinessClass.GetItemMasterByItemCode(lngId); try { if (objML_ItemMaster != null) { objML_ItemMaster.CanteenCode = Convert.ToInt32(ML_Common.clean(ddlCanteenName.SelectedValue)); objML_ItemMaster.CategoryGroupCode = Convert.ToInt32(ML_Common.clean(ddlCategoryGroupCode.SelectedValue)); objML_ItemMaster.ItemCategoryCode = Convert.ToInt32(ML_Common.clean(ddlCategoryItemCode.SelectedValue)); objML_ItemMaster.ItemName = ML_Common.clean(txtItemNameEdit.Text); objML_ItemMaster.ItemEmployeeRate = Convert.ToDecimal(ML_Common.clean(txtItemEmployeeRateEdit.Text)); if (ChStatusEdit.Checked) { objML_ItemMaster.ItemActive = 1; } else { objML_ItemMaster.ItemActive = 0; } int obhReturn = objBusinessClass.UpdateItemMaster(objML_ItemMaster); if (obhReturn == 1) { lblMsg.Visible = true; lblMsg.Text = "Record Update Successfully"; } else if (obhReturn == 2) { lblMsg.Text = "Ooops!OtherIssue..."; lblMsg.Visible = true; } else { lblMsg.Text = "Ooops!OtherIssue..."; lblMsg.Visible = true; } grdItemMaster.EditIndex = -1; FillGrid(); } } catch (SqlException sqlExc) { SqlException sqlEt = sqlExc; return; } catch (Exception ex) { Exception exc = ex;// LogManager.LogManager.WriteErrorLog(ex); } } }