Exemple #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   lbldeduct_doc = (Label)GridView1.Rows[e.RowIndex].FindControl("lbldeduct_doc");
            cDeduct oDeduct       = new cDeduct();

            try
            {
                oDeduct.SP_DEDUCT_HEAD_DEL(lbldeduct_doc.Text);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oDeduct.Dispose();
            }
            BindGridView(0);
        }
        private bool SaveDetail()
        {
            bool    blnResult = false;
            cDeduct oDeduct   = new cDeduct();

            try
            {
                string strUserName = Session["username"].ToString();
                StoreDetail();
                foreach (DataRow dr in this.dtDeductDetail.Rows)
                {
                    if (Helper.CStr(dr["recv_item_code"]).Trim().Length > 0)
                    {
                        var detail = new Deduct_detail
                        {
                            deduct_doc_no           = txtdeduct_doc.Text,
                            deduct_detail_id        = Helper.CLong(dr["deduct_detail_id"]),
                            recv_item_code          = Helper.CStr(dr["recv_item_code"]),
                            recv_item_rate          = Helper.CDec(dr["recv_item_rate"]),
                            deduct_item_amount      = Helper.CDec(dr["deduct_item_amount"]),
                            deduct_item_is_director = Helper.CBool(dr["deduct_item_is_director"]),
                            deduct_item_remark      = Helper.CStr(dr["deduct_item_remark"]),
                            c_created_by            = strUserName,
                            c_updated_by            = strUserName
                        };
                        if (Helper.CStr(dr["row_status"]) == "N")
                        {
                            oDeduct.SP_DEDUCT_DETAIL_INS(detail);
                        }
                        else if (Helper.CStr(dr["row_status"]) == "O")
                        {
                            oDeduct.SP_DEDUCT_DETAIL_UPD(detail);
                        }
                        else if (Helper.CStr(dr["row_status"]) == "D")
                        {
                            oDeduct.SP_DEDUCT_DETAIL_DEL(detail.deduct_detail_id);
                        }
                    }
                }
                this.dtDeductDetail = null;
                blnResult           = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oDeduct.Dispose();
            }
            return(blnResult);
        }
Exemple #3
0
        private bool saveData()
        {
            bool   blnResult    = false;
            string strUpdatedBy = string.Empty;

            strUpdatedBy = Session["username"].ToString();
            CheckBox      chkSelect;
            Label         lblrecv_item_code        = null;
            Label         lblrecv_item_name        = null;
            AwNumeric     txtrecv_item_rate        = null;
            CheckBox      chkRecv_item_is_director = null;
            var           oDeduct       = new cDeduct();
            Deduct_detail deduct_detail = null;

            try
            {
                foreach (GridViewRow gvRow in GridView1.Rows)
                {
                    chkSelect = (CheckBox)gvRow.FindControl("chkSelect");
                    var select = Request.Form[chkSelect.UniqueID];
                    if (select != null && select == "on")
                    {
                        lblrecv_item_code        = (Label)gvRow.FindControl("lblrecv_item_code");
                        lblrecv_item_name        = (Label)gvRow.FindControl("lblrecv_item_name");
                        txtrecv_item_rate        = (AwNumeric)gvRow.FindControl("txtrecv_item_rate");
                        chkRecv_item_is_director = (CheckBox)gvRow.FindControl("chkRecv_item_is_director");
                        var recv_item_rate = decimal.Parse(txtrecv_item_rate.Value.ToString());
                        deduct_detail = new Deduct_detail
                        {
                            deduct_doc_no           = ViewState["deduct_doc"].ToString(),
                            recv_item_code          = lblrecv_item_code.Text,
                            recv_item_rate          = recv_item_rate,
                            deduct_item_amount      = decimal.Parse(ViewState["recv_total_amount"].ToString()) * recv_item_rate / 100,
                            deduct_item_is_director = chkRecv_item_is_director.Checked,
                            c_created_by            = strUpdatedBy
                        };
                        oDeduct.SP_DEDUCT_DETAIL_INS(deduct_detail);
                    }
                    blnResult = true;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
            finally
            {
                oDeduct.Dispose();
            }
            return(blnResult);
        }
Exemple #4
0
        private void BindGridView(int nPageNo)
        {
            var     oDeduct     = new cDeduct();
            DataSet ds          = new DataSet();
            string  strMessage  = string.Empty;
            string  strCriteria = string.Empty;
            var     deduct_head = new view_Deduct_head();
            string  strScript   = string.Empty;

            #region Criteria
            deduct_head.deduct_year            = cboYear.SelectedValue;
            deduct_head.degree_code            = cboDegree.SelectedValue;
            deduct_head.deduct_doc_no          = txtdeduct_doc.Text.Replace("'", "''").Trim();
            deduct_head.budget_plan_code       = txtbudget_plan_code.Text.Replace("'", "''").Trim();
            deduct_head.unit_code              = cboUnit.SelectedValue;
            deduct_head.budget_code            = cboBudget.SelectedValue;
            deduct_head.produce_code           = cboProduce.SelectedValue;
            deduct_head.activity_code          = cboActivity.SelectedValue;
            deduct_head.plan_code              = cboPlan_code.SelectedValue;
            deduct_head.item_group_detail_code = cboItem_group_detail.SelectedValue;

            if (!deduct_head.deduct_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (deduct_year = '" + deduct_head.deduct_year + "') ";
            }
            if (!deduct_head.degree_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (degree_code = '" + deduct_head.degree_code + "') ";
            }
            if (!string.IsNullOrEmpty(txtdate_begin.Text))
            {
                strCriteria = strCriteria + "  And  (deduct_date >= '" + cCommon.SeekDate(txtdate_begin.Text) + "') ";
            }

            if (!string.IsNullOrEmpty(txtdate_end.Text))
            {
                strCriteria = strCriteria + "  And  (deduct_date <= '" + cCommon.SeekDate(txtdate_end.Text) + "') ";
            }

            if (!deduct_head.deduct_doc_no.Equals(""))
            {
                strCriteria = strCriteria + "  And  (deduct_doc_no LIKE '%" + deduct_head.deduct_doc_no + "%') ";
            }

            if (!deduct_head.budget_plan_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (budget_plan_code ='" + deduct_head.budget_plan_code + "') ";
            }

            if (!deduct_head.unit_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (unit_code ='" + deduct_head.unit_code + "') ";
            }

            if (!deduct_head.budget_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (budget_code ='" + deduct_head.budget_code + "') ";
            }

            if (!deduct_head.produce_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (produce_code ='" + deduct_head.produce_code + "') ";
            }

            if (!deduct_head.activity_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (activity_code = '" + deduct_head.activity_code + "') ";
            }

            if (!deduct_head.plan_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (plan_code = '" + deduct_head.plan_code + "') ";
            }


            if (!deduct_head.item_group_detail_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_group_detail_code = '" + deduct_head.item_group_detail_code + "') ";
            }

            if (DirectorLock == "Y")
            {
                strCriteria += " and substring(director_code,4,2) = substring('" + DirectorCode + "',4,2) ";
            }

            #endregion

            //strCriteria = strCriteria + " and budget_type ='" + this.BudgetType + "' ";

            try
            {
                if (!oDeduct.SP_DEDUCT_HEAD_SEL(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
            {
                oDeduct.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
        private bool saveData()
        {
            bool        blnResult   = false;
            Deduct_head deduct_head = new Deduct_head();
            cDeduct     oDeduct     = new cDeduct();

            try
            {
                #region set Data
                deduct_head.deduct_doc_no      = txtdeduct_doc.Text;
                deduct_head.deduct_year        = cboYear.SelectedValue;
                deduct_head.deduct_date        = cCommon.GetDate(txtdeduct_date.Text);
                deduct_head.budget_money_doc   = txtbudget_money_doc.Text;
                deduct_head.budget_receive_doc = txtbudget_receive_doc.Text;
                deduct_head.major_code         = cboMajor.SelectedValue;
                deduct_head.degree_code        = cboDegree.SelectedValue;

                deduct_head.recv_doc_no                  = txtrecv_doc_no.Text;
                deduct_head.recv_total_amount            = decimal.Parse(txtrecv_total_amount.Value.ToString());
                deduct_head.deduct_total_reduce          = decimal.Parse(txtdeduct_total_reduce.Value.ToString());
                deduct_head.deduct_total_reduce_director = decimal.Parse(txtdeduct_total_reduce_director.Value.ToString());
                deduct_head.deduct_total_remain          = decimal.Parse(txtdeduct_total_remain.Value.ToString());

                deduct_head.budget_plan_code     = txtbudget_plan_code.Text;
                deduct_head.deduct_remark        = txtcomment.Text.Trim();
                deduct_head.item_group_detail_id = int.Parse(cboItem_group_detail.SelectedValue);
                deduct_head.c_created_by         = Session["username"].ToString();
                deduct_head.c_updated_by         = Session["username"].ToString();
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    if (oDeduct.SP_DEDUCT_HEAD_UPD(deduct_head))
                    {
                        SaveDetail();
                        saveBudgetReceive();
                    }
                }
                else
                {
                    oDeduct.SP_DEDUCT_HEAD_INS(deduct_head);
                    ViewState["deduct_doc"] = deduct_head.deduct_doc_no;
                    saveBudgetReceive();
                    deduct_head.budget_receive_doc = txtbudget_receive_doc.Text;
                    oDeduct.SP_DEDUCT_HEAD_UPD(deduct_head);
                }

                blnResult = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    MsgBox("ข้อมูลซ้ำโปรดตรวจสอบ");
                }
                else
                {
                    //lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oDeduct.Dispose();
            }
            return(blnResult);
        }