예제 #1
0
        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     lbldirector_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lbldirector_code");
            cDirector oDirector        = new cDirector();

            try
            {
                if (!oDirector.SP_DEL_DIRECTOR(lbldirector_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oDirector.Dispose();
            }
            BindGridView(0);
        }
예제 #2
0
        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     lbldirector_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lbldirector_code");
            cDirector oDirector        = new cDirector();

            try
            {
                if (!oDirector.SP_DEL_DIRECTOR(lbldirector_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    if (strMessage.Contains("REFERENCE constraint"))
                    {
                        MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                    }
                    else
                    {
                        lblError.Text = strMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oDirector.Dispose();
            }
            BindGridView(0);
        }
예제 #3
0
        private void BindgridDirector()
        {
            cDirector oDirector   = new cDirector();
            DataSet   ds          = new DataSet();
            string    strMessage  = string.Empty;
            string    strCriteria = string.Empty;
            string    strYear     = string.Empty;

            strYear     = cboYear.SelectedValue;
            strCriteria = " And (director_year='" + strYear + "')  ";

            try
            {
                #region Diector
                if (!oDirector.SP_SEL_DIRECTOR(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                    gridDirector.DataSource       = ds.Tables[0];
                    gridDirector.DataBind();
                }
                #endregion
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oDirector.Dispose();
                ds.Dispose();
            }
        }
예제 #4
0
        private bool saveData()
        {
            bool   blnResult              = false;
            bool   blnDup                 = false;
            string strMessage             = string.Empty;
            string strdirector_code       = string.Empty,
                   strdirector_year       = string.Empty,
                   strdirector_name       = string.Empty,
                   strdirector_sign_name  = string.Empty,
                   strdirector_sign_image = string.Empty,
                   strsign_position       = string.Empty,
                   strActive              = string.Empty,
                   strCreatedBy           = string.Empty,
                   strUpdatedBy           = string.Empty,
                   strBudget_type         = string.Empty;
            string    strScript           = string.Empty;
            cDirector oDirector           = new cDirector();
            DataSet   ds = new DataSet();

            try
            {
                #region set Data
                strdirector_code      = txtdirector_code.Text.Trim();
                strdirector_name      = txtdirector_name.Text;
                strdirector_year      = cboYear.SelectedItem.Value;
                strdirector_sign_name = txtdirector_sign_name.Text;
                strsign_position      = txtsign_position.Text;
                strBudget_type        = cboBudget_type.SelectedItem.Value;
                if (txtdirector_sign_image.Text.Length > 0)
                {
                    strdirector_sign_image = MapPath("~/person_pic/" + txtdirector_sign_image.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 (strdirector_sign_image != "")
                        {
                            if (oDirector.SP_UPD_DIRECTOR(strdirector_code, strdirector_year, strdirector_name, strdirector_sign_name, strdirector_sign_image, strsign_position, txtdirector_order.Value.ToString(), strActive, strUpdatedBy, strBudget_type, ref strMessage))
                            {
                                blnResult = true;
                            }
                            else
                            {
                                lblError.Text = strMessage.ToString();
                            }
                        }
                        else
                        {
                            if (oDirector.SP_UPD_NOIMAGE_DIRECTOR(strdirector_code, strdirector_year, strdirector_name, strdirector_sign_name, strsign_position, txtdirector_order.Value.ToString(), strActive, strUpdatedBy, strBudget_type, 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 director_name = '" + strdirector_name.Trim() + "' and director_year = '" + strdirector_year + "' ";
                    if (!oDirector.SP_SEL_DIRECTOR(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strdirector_name.Trim() + " ปี " + strdirector_year.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oDirector.SP_INS_DIRECTOR(strdirector_year, strdirector_name, strdirector_sign_name, strdirector_sign_image, strsign_position, txtdirector_order.Value.ToString(), strActive, strCreatedBy, strBudget_type, ref strMessage))
                        {
                            string strGetcode = " and director_name = '" + strdirector_name.Trim() + "' and director_year = '" + strdirector_year + "' ";
                            if (!oDirector.SP_SEL_DIRECTOR(strGetcode, ref ds, ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                strdirector_code = ds.Tables[0].Rows[0]["director_code"].ToString();
                            }
                            ViewState["director_code"] = strdirector_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
            {
                oDirector.Dispose();
            }
            return(blnResult);
        }
예제 #5
0
        private void BindGridView(int nPageNo)
        {
            cDirector oDirector        = new cDirector();
            DataSet   ds               = new DataSet();
            string    strMessage       = string.Empty;
            string    strCriteria      = string.Empty;
            string    strdirector_code = string.Empty;
            string    strdirector_name = string.Empty;
            string    strActive        = string.Empty;
            string    strdirector_year = string.Empty;

            strdirector_code = txtdirector_code.Text.Replace("'", "''").Trim();
            strdirector_name = txtdirector_name.Text.Replace("'", "''").Trim();
            strdirector_year = cboYear.SelectedValue;
            if (!strdirector_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (director_code like '%" + strdirector_code + "%') ";
            }
            if (!strdirector_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (director_name like '%" + strdirector_name + "%')";
            }
            if (!strdirector_year.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (director_year = '" + strdirector_year + "') ";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }
            try
            {
                if (!oDirector.SP_SEL_DIRECTOR(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
            {
                oDirector.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }