Ejemplo n.º 1
0
        private bool saveData()
        {
            bool       blnResult  = false;
            string     strScript  = string.Empty;
            cRecv_item oRecv_Item = new cRecv_item();
            DataSet    ds         = new DataSet();

            try
            {
                #region set Data
                var recv_item = new Recv_item()
                {
                    recv_item_code        = txtrecv_item_code.Text.Trim(),
                    recv_item_name        = txtrecv_item_name.Text,
                    recv_item_remark      = txtrecv_item_remark.Text.Trim(),
                    recv_item_year        = cboYear.SelectedItem.Value,
                    recv_item_rate        = decimal.Parse(txtrecv_item_rate.Value.ToString()),
                    recv_item_is_director = chkRecv_item_is_director.Checked,
                    recv_item_type        = cboRecv_item_type.SelectedValue,
                    c_active     = chkStatus.Checked ? "Y" : "N",
                    c_created_by = Session["username"].ToString(),
                    c_updated_by = Session["username"].ToString()
                };
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    oRecv_Item.SP_RECV_ITEM_UPD(recv_item);
                }
                else
                {
                    oRecv_Item.SP_RECV_ITEM_INS(recv_item);
                }
                blnResult = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    strScript = @"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก";
                    //if (ex.Message.Contains("IX_recv_item_group_detail_code"))
                    //{
                    //    strScript += "ข้อมูลรหัสรายละเอียดหมวดค่าใช้จ่าย : " + txtrecv_item_group_detail_code.Text + " ซ้ำ";
                    //}
                    //else if (ex.Message.Contains("IX_recv_item_group_detail_name"))
                    //{
                    //    strScript += "ข้อมูลรายละเอียดหมวดค่าใช้จ่าย : " + txtrecv_item_group_detail_name.Text + " ซ้ำ";
                    //}
                    MsgBox(strScript);
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oRecv_Item.Dispose();
            }
            return(blnResult);
        }
Ejemplo n.º 2
0
        public Recv_item GET(string strCriteria)
        {
            Recv_item result     = null;
            var       strMessage = string.Empty;
            DataSet   ds         = null;

            if (SP_RECV_ITEM_SEL(strCriteria, ref ds, ref strMessage))
            {
                result = Helper.ToClassInstanceCollection <Recv_item>(ds.Tables[0]).FirstOrDefault();
            }
            return(result);
        }
Ejemplo n.º 3
0
        public bool SP_RECV_ITEM_INS(Recv_item Recv_item)
        {
            bool           blnResult = false;
            SqlConnection  oConn     = new SqlConnection();
            SqlCommand     oCommand  = new SqlCommand();
            SqlDataAdapter oAdapter  = new SqlDataAdapter();

            try
            {
                oConn.ConnectionString = _strConn;
                oConn.Open();
                oCommand.Connection  = oConn;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.CommandText = "sp_RECV_ITEM_INS";
                oCommand.Parameters.Add("recv_item_code", SqlDbType.VarChar).Value    = Recv_item.recv_item_code;
                oCommand.Parameters.Add("recv_item_year", SqlDbType.VarChar).Value    = Recv_item.recv_item_year;
                oCommand.Parameters.Add("recv_item_name", SqlDbType.VarChar).Value    = Recv_item.recv_item_name;
                oCommand.Parameters.Add("recv_item_type", SqlDbType.VarChar).Value    = Recv_item.recv_item_type;
                oCommand.Parameters.Add("recv_item_rate", SqlDbType.Money).Value      = Recv_item.recv_item_rate;
                oCommand.Parameters.Add("recv_item_remark", SqlDbType.VarChar).Value  = Recv_item.recv_item_remark;
                oCommand.Parameters.Add("recv_item_is_director", SqlDbType.Bit).Value = Recv_item.recv_item_is_director;
                oCommand.Parameters.Add("c_active", SqlDbType.VarChar).Value          = Recv_item.c_active;
                oCommand.Parameters.Add("c_created_by", SqlDbType.VarChar).Value      = Recv_item.c_created_by;
                oCommand.ExecuteNonQuery();
                blnResult = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConn.Close();
                oCommand.Dispose();
                oConn.Dispose();
            }
            return(blnResult);
        }
Ejemplo n.º 4
0
        private void BindGridView(int nPageNo)
        {
            InitcboYear();
            cRecv_item oRecv_item  = new cRecv_item();
            DataSet    ds          = new DataSet();
            string     strMessage  = string.Empty;
            string     strCriteria = string.Empty;
            var        recv_item   = new Recv_item
            {
                recv_item_year = cboYear.SelectedValue,
                recv_item_code = txtrecv_item_code.Text.Replace("'", "''").Trim(),
                recv_item_name = txtrecv_item_name.Text.Replace("'", "''").Trim(),
            };

            if (!recv_item.recv_item_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_year = '" + recv_item.recv_item_year + "') ";
            }
            if (!recv_item.recv_item_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_code like '%" + recv_item.recv_item_code + "%') ";
            }
            if (!recv_item.recv_item_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_name like '%" + recv_item.recv_item_name + "%') ";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }

            try
            {
                if (!oRecv_item.SP_RECV_ITEM_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
            {
                oRecv_item.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Ejemplo n.º 5
0
        private void BindGridView()
        {
            cRecv_item oRecv_item  = new cRecv_item();
            DataSet    ds          = new DataSet();
            string     strMessage  = string.Empty;
            string     strCriteria = string.Empty;
            var        recv_item   = new Recv_item();
            string     strScript   = string.Empty;

            recv_item.recv_item_year = ViewState["recv_item_year"].ToString();
            recv_item.recv_item_code = txtrecv_item_code.Text.Replace("'", "''").Trim();
            recv_item.recv_item_name = txtrecv_item_name.Text.Replace("'", "''").Trim();
            recv_item.recv_item_type = cboRecv_item_type.SelectedValue;;

            if (!recv_item.recv_item_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_year = '" + recv_item.recv_item_year + "') ";
            }
            if (!recv_item.recv_item_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_code = '" + recv_item.recv_item_code + "') ";
            }

            if (!recv_item.recv_item_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_name = '" + recv_item.recv_item_name + "') ";
            }

            if (!recv_item.recv_item_type.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_type = '" + recv_item.recv_item_type + "') ";
            }

            if (ViewState["deduct_doc"] != null)
            {
                strCriteria = strCriteria + "  And  recv_item_code NOT IN (SELECT recv_item_code from Deduct_detail WHERE deduct_doc_no = '" + ViewState["deduct_doc"].ToString() + "') ";
            }

            try
            {
                if (oRecv_item.SP_RECV_ITEM_SEL(strCriteria, ref ds, ref strMessage))
                {
                    ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                    GridView1.DataSource          = ds.Tables[0];
                    GridView1.DataBind();
                }
                else
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oRecv_item.Dispose();
                ds.Dispose();
            }
        }