protected void imgBtnInsert_Click(object sender, ImageClickEventArgs e) { try { if (Session["LabelMaintData"] != null) { DataTable dtLabelData = Session["LabelMaintData"] as DataTable; if (dtLabelData.Select("label_code = '" + txtLabelCode.Text + "'").Length != 0) { msgView.SetMessage("Label already exists with this label code.", MessageType.Success, PositionType.Auto); return; } } string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); labelMaintenanceBL = new LabelMaintenanceBL(); DataSet labelData = labelMaintenanceBL.InsertLabelData(txtLabelCode.Text.Trim(), txtLabelDesc.Text.Trim(), userCode, out errorId); labelMaintenanceBL = null; if (labelData.Tables.Count != 0 && errorId != 2) { Session["LabelMaintData"] = labelData.Tables[0]; Session["FuzzySearchAllLabelList"] = labelData.Tables[1]; BindGrid(labelData.Tables[0]); txtLabelDesc.Text = string.Empty; txtLabelCode.Text = string.Empty; txtLabelSearch.Text = string.Empty; hdnChangeNotSaved.Value = "N"; hdnInsertDataNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Label created successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to create label.", MessageType.Warning, PositionType.Auto); } } catch (Exception ex) { ExceptionHandler("Error in creating label.", ex.Message); } }
protected void btnSaveChanges_Click(object sender, EventArgs e) { try { if (hdnInsertDataNotSaved.Value == "Y") { //Validate Page.Validate("valInsertLabel"); if (!Page.IsValid) { mpeSaveUndo.Hide(); msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto); return; } if (Session["LabelMaintData"] != null) { DataTable dtLabelData = Session["LabelMaintData"] as DataTable; if (dtLabelData.Select("label_code = '" + txtLabelCode.Text + "'").Length != 0) { msgView.SetMessage("Label already exists with this label code.", MessageType.Success, PositionType.Auto); return; } } string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); labelMaintenanceBL = new LabelMaintenanceBL(); DataSet labelData = labelMaintenanceBL.InsertLabelData(txtLabelCode.Text.Trim(), txtLabelDesc.Text.Trim(), userCode, out errorId); labelMaintenanceBL = null; if (labelData.Tables.Count != 0 && errorId != 2) { Session["LabelMaintData"] = labelData.Tables[0]; Session["FuzzySearchAllLabelList"] = labelData.Tables[1]; BindGrid(labelData.Tables[0]); txtLabelDesc.Text = string.Empty; txtLabelCode.Text = string.Empty; txtLabelSearch.Text = string.Empty; hdnChangeNotSaved.Value = "N"; hdnInsertDataNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Label created successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed create label.", MessageType.Warning, PositionType.Auto); } } else if (hdnChangeNotSaved.Value == "Y") { //Validate Page.Validate("valUpdateLabel"); if (!Page.IsValid) { mpeSaveUndo.Hide(); msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto); return; } string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); int rowIndex = Convert.ToInt32(hdnGridRowSelectedPrvious.Value); string labelCode = ((Label)gvLabelDetails.Rows[rowIndex].FindControl("lblLabelCode")).Text; string labelDesc = ((TextBox)gvLabelDetails.Rows[rowIndex].FindControl("txtLabelName")).Text; labelMaintenanceBL = new LabelMaintenanceBL(); DataSet labelData = labelMaintenanceBL.UpdateLabelData(labelCode, labelDesc, userCode, out errorId); labelMaintenanceBL = null; if (labelData.Tables.Count != 0 && errorId != 2) { Session["LabelMaintData"] = labelData.Tables[0]; Session["FuzzySearchAllLabelList"] = labelData.Tables[1]; //check if there is only one row in the grid before binding updated data. //if count is 1 then only display that row if (gvLabelDetails.Rows.Count == 1) { DataTable dtSearched = labelData.Tables[0].Clone(); DataRow[] foundRows = labelData.Tables[0].Select("label_code = '" + labelCode + "'"); if (foundRows.Length != 0) { dtSearched = foundRows.CopyToDataTable(); BindGrid(dtSearched); } } else { BindGrid(labelData.Tables[0]); } hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Label details updated successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to updated label details.", MessageType.Warning, PositionType.Auto); } } } catch (Exception ex) { ExceptionHandler("Error in saving grid data", ex.Message); } }