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; } } }
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); }