private bool saveData() { bool blnResult = false; int intdoctype_code; string strdoctype_name = string.Empty, strUserName = string.Empty, strScript = string.Empty; cefDoctype objefDoctype = new cefDoctype(); DataSet ds = new DataSet(); try { #region set Data intdoctype_code = Helper.CInt(txtdoctype_code.Text); strdoctype_name = txtdoctype_name.Text; strUserName = Session["username"].ToString(); #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { blnResult = objefDoctype.SP_DOCTYPE_UPD(intdoctype_code, strdoctype_name, strUserName); } else { #region insert if (objefDoctype.SP_DOCTYPE_INS(ref intdoctype_code, strdoctype_name, strUserName)) { ViewState["ef_doctype_code"] = intdoctype_code; blnResult = true; } #endregion } } catch (Exception ex) { if (ex.Message.Contains("duplicate") && ex.Message.Contains("IX_ef_doctype_name")) { strScript = "alert(\"ไม่สามารถแก้ไขข้อมูล เนื่องจากข้อมูล " + strdoctype_name.Trim() + " ซ้ำ\");\n"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } else { lblError.Text = ex.Message.ToString(); } } finally { objefDoctype.Dispose(); } return(blnResult); }
private void BindGridView(int nPageNo) { cefDoctype objEfDoctype = new cefDoctype(); DataTable dt; string strMessage = string.Empty; string strCriteria = string.Empty; string stref_doctype_name = string.Empty; stref_doctype_name = txtef_doctype_name.Text.Replace("'", "''").Trim(); if (!stref_doctype_name.Equals("0")) { strCriteria = strCriteria + " And (ef_doctype_name like '%" + stref_doctype_name + "%')"; } try { dt = objEfDoctype.SP_DOCTYPE_SEL(strCriteria); try { GridView1.PageIndex = nPageNo; txthTotalRecord.Value = dt.Rows.Count.ToString(); dt.DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = dt; GridView1.DataBind(); } catch { GridView1.PageIndex = 0; txthTotalRecord.Value = dt.Rows.Count.ToString(); dt.DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = dt; GridView1.DataBind(); } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { objEfDoctype.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
private void setData() { cefDoctype objECefDoctype = new cefDoctype(); DataTable dt; string strMessage = string.Empty, strCriteria = string.Empty; string strdoctype_code = string.Empty, strdoctype_name = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and ef_doctype_code = '" + ViewState["ef_doctype_code"].ToString() + "' "; dt = objECefDoctype.SP_DOCTYPE_SEL(strCriteria); if (dt.Rows.Count > 0) { #region get Data strdoctype_code = dt.Rows[0]["ef_doctype_code"].ToString(); strdoctype_name = dt.Rows[0]["ef_doctype_name"].ToString(); strCreatedBy = dt.Rows[0]["c_created_by"].ToString(); strUpdatedBy = dt.Rows[0]["c_updated_by"].ToString(); strCreatedDate = dt.Rows[0]["d_created_date"].ToString(); strUpdatedDate = dt.Rows[0]["d_updated_date"].ToString(); #endregion #region set Control txtdoctype_code.Text = strdoctype_code; txtdoctype_name.Text = strdoctype_name; txtUpdatedBy.Text = strUpdatedBy; txtUpdatedDate.Text = strUpdatedDate; #endregion } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string strMessage = string.Empty; string strScript = string.Empty; Label lblef_doctype_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblef_doctype_code"); cefDoctype objEfDoctype = new cefDoctype(); try { objEfDoctype.SP_DOCTYPE_DEL(Helper.CInt(lblef_doctype_code.Text)); } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { objEfDoctype.Dispose(); } BindGridView(0); }