private void setData() { cTitle oTitle = new cTitle(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; string strTitle_code = string.Empty, strTitle_name = string.Empty, strC_active = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and title_code = '" + ViewState["title_code"].ToString() + "' "; if (!oTitle.SP_SEL_TITLE(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data strTitle_code = ds.Tables[0].Rows[0]["title_code"].ToString(); strTitle_name = ds.Tables[0].Rows[0]["title_name"].ToString(); strC_active = ds.Tables[0].Rows[0]["c_active"].ToString(); strCreatedBy = ds.Tables[0].Rows[0]["c_created_by"].ToString(); strUpdatedBy = ds.Tables[0].Rows[0]["c_updated_by"].ToString(); strCreatedDate = ds.Tables[0].Rows[0]["d_created_date"].ToString(); strUpdatedDate = ds.Tables[0].Rows[0]["d_updated_date"].ToString(); #endregion #region set Control txttitle_code.Text = strTitle_code; txttitle_name.Text = strTitle_name; if (strC_active.Equals("Y")) { txttitle_name.ReadOnly = false; txttitle_name.CssClass = "textbox"; chkStatus.Checked = true; } else { txttitle_name.ReadOnly = true; txttitle_name.CssClass = "textboxdis"; chkStatus.Checked = false; } 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 strCheck = string.Empty; string strScript = string.Empty; string strUpdatedBy = Session["username"].ToString(); Label lbltitle_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lbltitle_code"); cTitle oTitle = new cTitle(); try { if (!oTitle.SP_DEL_TITLE(lbltitle_code.Text, "N", strUpdatedBy, ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oTitle.Dispose(); } BindGridView(0); }
/// <summary> /// Creates a cTitle object. It will be saved in permanent storage only /// on calling Save() /// </summary> /// <returns>cTitle object</returns> public static cTitle Create() { cTitle oObj = new cTitle(); SecurityCheck((int)enTitle_Action.Create); // Create an object in memory, will be saved to storage on calling Save() oObj.m_bCreating = true; oObj.m_bInvalid = false; return(oObj); }
/// <summary> /// Ensures that an object with the specified name exists, while creating other properties are set to their default values /// </summary> /// <param name="i_sName">Name</param> /// <returns>cTitle object</returns> public static cTitle CreateIfRequiredAndGet(string i_sName) { cTitle oObj = cTitle.Get_Name(i_sName); if (oObj == null) { oObj = cTitle.Create(); oObj.sName = i_sName; oObj.Save(); } return(oObj); }
/// <summary> /// Finds and return cTitle objects matching the specified criteria /// </summary> /// <param name="i_oFilter">Filter criteria (WHERE clause)</param> /// <returns>cTitle objects</returns> public static List <cTitle> Find(cFilter i_oFilter) { DataTable dt = Find_DataTable(i_oFilter, null); List <cTitle> l = new List <cTitle>(); cTitle oObj; for (int i = 0; i < dt.Rows.Count; i++) { oObj = new cTitle(); oObj.m_iID = Convert.ToInt32(dt.Rows[i]["iID"]); oObj.m_sName = dt.Rows[i]["sName"].ToString(); oObj.m_dtCreatedOn = Convert.ToDateTime(dt.Rows[i]["dtCreatedOn"]); oObj.m_dtLastUpdatedOn = Convert.ToDateTime(dt.Rows[i]["dtLastUpdatedOn"]); oObj.m_bIsActive = Convert.ToBoolean(dt.Rows[i]["bIsActive"]); oObj.m_bInvalid = false; l.Add(oObj); } return(l); }
private void BindGridView(int nPageNo) { cTitle oTitle = new cTitle(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strTitle_code = string.Empty; string strTitle_name = string.Empty; string strActive = string.Empty; strTitle_code = txttitle_code.Text.Replace("'", "''").Trim(); strTitle_name = txttitle_name.Text.Replace("'", "''").Trim(); if (!strTitle_code.Equals("0")) { strCriteria = strCriteria + " And (title_code like '%" + strTitle_code + "%') "; } if (!strTitle_name.Equals("0")) { strCriteria = strCriteria + " And (title_name like '%" + strTitle_name + "%')"; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (c_active ='N') "; } try { if (!oTitle.SP_SEL_TITLE(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { try { GridView1.PageIndex = nPageNo; txthTotalRecord.Value = ds.Tables[0].Rows.Count.ToString(); ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch { GridView1.PageIndex = 0; txthTotalRecord.Value = ds.Tables[0].Rows.Count.ToString(); ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oTitle.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
using System;
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string strtitle_code = string.Empty, strtitle_name = string.Empty, strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cTitle oTitle = new cTitle(); DataSet ds = new DataSet(); try { #region set Data strtitle_code = txttitle_code.Text.Trim(); strtitle_name = txttitle_name.Text; if (chkStatus.Checked == true) { strActive = "Y"; } else { strActive = "N"; } strCreatedBy = Session["username"].ToString(); strUpdatedBy = Session["username"].ToString(); #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { #region edit if (!blnDup) { if (oTitle.SP_UPD_TITLE(strtitle_code, strtitle_name, strActive, strUpdatedBy, ref strMessage)) { blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } else { #region check dup string strCheckDup = string.Empty; strCheckDup = " and title_code = '" + strtitle_code.Trim() + "' "; if (!oTitle.SP_SEL_TITLE(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strtitle_code.Trim() + " : " + strtitle_name.Trim() + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oTitle.SP_INS_TITLE(strtitle_code, strtitle_name, strActive, strCreatedBy, ref strMessage)) { ViewState["title_code"] = strtitle_code; blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oTitle.Dispose(); } return(blnResult); }