private void BindGridView() { c3dCount obj3dCount = new c3dCount(); string strMessage = string.Empty; string strCriteria = string.Empty; string strcount_name = string.Empty; string strcount_id = string.Empty; string strScript = string.Empty; strcount_name = txtcount_name.Text.Replace("'", "''").Trim(); if (!strcount_name.Equals("")) { strCriteria = strCriteria + " And (count_name like '%" + strcount_name + "%') "; } try { var dt = obj3dCount.SP_COUNT_SEL(strCriteria); if (dt.Rows.Count == 1) { strcount_id = dt.Rows[0]["count_id"].ToString(); strcount_name = dt.Rows[0]["count_name"].ToString(); if (!ViewState["show"].ToString().Equals("1")) { strScript = "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strcount_id + "';\n " + "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strcount_name + "';\n " + "ClosePopUp('" + ViewState["show"].ToString() + "');"; } else { strScript = "window.parent.document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strcount_id + "';\n" + "window.parent.document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strcount_name + "';\n" + "ClosePopUp('" + ViewState["show"].ToString() + "');"; } ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true); } else { dt.DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = dt; GridView1.DataBind(); } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { obj3dCount.Dispose(); } }
private bool saveData() { bool blnResult = false; int intcount_id; string strcount_name = string.Empty, strUserName = string.Empty, strScript = string.Empty; c3dCount obj3dCount = new c3dCount(); try { #region set Data intcount_id = Helper.CInt(txtcount_id.Text); strcount_name = txtcount_name.Text; strUserName = Session["username"].ToString(); #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { blnResult = obj3dCount.SP_COUNT_UPD(intcount_id, strcount_name, strUserName); } else { #region insert if (obj3dCount.SP_COUNT_INS(ref intcount_id, strcount_name, strUserName)) { ViewState["count_id"] = intcount_id; blnResult = true; } #endregion } } catch (Exception ex) { if (ex.Message.Contains("duplicate") && ex.Message.Contains("IX_count_name")) { strScript = "alert(\"ไม่สามารถแก้ไขข้อมูล เนื่องจากข้อมูล " + strcount_name.Trim() + " ซ้ำ\");\n"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } else { lblError.Text = ex.Message.ToString(); } } finally { obj3dCount.Dispose(); } return(blnResult); }
private void BindGridView(int nPageNo) { c3dCount objEfDoctype = new c3dCount(); DataTable dt; string strMessage = string.Empty; string strCriteria = string.Empty; string strcount_name = string.Empty; strcount_name = txtcount_name.Text.Replace("'", "''").Trim(); if (!strcount_name.Equals("0")) { strCriteria = strCriteria + " And (count_name like '%" + strcount_name + "%')"; } try { dt = objEfDoctype.SP_COUNT_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() { c3dCount objECefDoctype = new c3dCount(); DataTable dt; string strMessage = string.Empty, strCriteria = string.Empty; string strcount_id = string.Empty, strcount_name = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and count_id = '" + ViewState["count_id"].ToString() + "' "; dt = objECefDoctype.SP_COUNT_SEL(strCriteria); if (dt.Rows.Count > 0) { #region get Data strcount_id = dt.Rows[0]["count_id"].ToString(); strcount_name = dt.Rows[0]["count_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 txtcount_id.Text = strcount_id; txtcount_name.Text = strcount_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 lblcount_id = (Label)GridView1.Rows[e.RowIndex].FindControl("lblcount_id"); c3dCount objEfDoctype = new c3dCount(); try { objEfDoctype.SP_COUNT_DEL(Helper.CInt(lblcount_id.Text)); } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { objEfDoctype.Dispose(); } BindGridView(0); }