Ejemplo n.º 1
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtlmoney.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาเลือกพนักงานก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtlmoney.Focus();
                return;
            }
            if (txtamountLoan.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนจำนวนชำระก่อน  !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtamountLoan.Focus();
                return;
            }

            LoanPayDetail loanPayDetail = new LoanPayDetail();

            loanPayDetail.LID = lid;
             string _date = String.Format("{0:dd/MM/yyyy}", DateTime.Now);
            loanPayDetail.lpdDate = _date;
            loanPayDetail.lpdamount =Convert.ToInt32(txtamountLoan.Text.ToString());

            int result = loanService.CreateLoanPayDetail(loanPayDetail);

            if (result > -1)
            {
                Console.WriteLine("Insert Complete");
                lblresult.Visible = true;
                lblresult.Text = " บันทึกเรียบร้อย ";
                //txtlmoney ค่ายอดเงินกู้
                List<LoanPayDetail> loanPayDetails = new List<LoanPayDetail>();
                loanPayDetails = loanService.getLoanPayDetailByID(lid);
                int sum = 0;
                foreach (LoanPayDetail lp in loanPayDetails) {

                    sum = sum + lp.lpdamount;
                }
                if (sum >= Convert.ToInt32(txtlmoney.Text.Trim())) {
                   // update complete =1
                    int rupdate = loanService.UpdateCompleteLoad(Convert.ToInt32(lid));
                    if (rupdate > -1)
                    {
                        Console.WriteLine("update Complete");
                        dgvList.DataSource = null;
                    }
                    else {
                        Console.WriteLine("update not Complete");
                    }
                }

                loadDefault();
            }
            else
            {
                Console.WriteLine("Insert Not Complete");
                lblresult.Visible = true;
                lblresult.Text = " ไม่สามารถบันทึกข้อมูลได้";

            }
        }
Ejemplo n.º 2
0
        public int CreateLoanPayDetail(LoanPayDetail newLoanPayDetail)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO tbLoanPayDetail(LID,loanDate,lamount)");
                sb.Append(" VALUES (@LID,@loanDate,@lamount)");

                string sqlsave;
                sqlsave = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.Transaction = tr;
                comm.CommandText = sqlsave;
                comm.Parameters.Clear();
                comm.Parameters.Add("@LID", SqlDbType.NVarChar).Value = newLoanPayDetail.LID;
                comm.Parameters.Add("@loanDate", SqlDbType.NVarChar).Value = newLoanPayDetail.lpdDate;
                comm.Parameters.Add("@lamount", SqlDbType.NVarChar).Value = newLoanPayDetail.lpdamount;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }
            return result;
        }
Ejemplo n.º 3
0
        public List<LoanPayDetail> getLoanPayDetailByID(string _lid)
        {
            List<LoanPayDetail> loanPayDetails = new List<LoanPayDetail>();
            LoanPayDetail loanPayDetail = null;

            try
            {
                conn = db.openConn();
                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append(" SELECT LID,loanDate,lamount FROM tbLoanPayDetail ");
                sb.Append(" WHERE LID='" + _lid + "'");

                string sql;
                sql = sb.ToString();

                comm = new SqlCommand();
                comm.CommandText = sql;
                comm.CommandType = CommandType.Text;
                comm.Connection = conn;
                dr = comm.ExecuteReader();
                if (dr.HasRows)
                {

                    DataTable dt = new DataTable();
                    dt.Load(dr);
                    foreach (DataRow drw in dt.Rows)
                    {
                        loanPayDetail = new LoanPayDetail();
                        loanPayDetail.LID = drw["LID"].ToString();
                        loanPayDetail.lpdDate = drw["loanDate"].ToString();
                        loanPayDetail.lpdamount =Convert.ToInt32(drw["lamount"].ToString());
                        loanPayDetails.Add(loanPayDetail);
                    }

                }

                dr.Close();

            }
            catch (Exception ex)
            {
                dr.Close();
                conn.Close();
                return null;
                throw ex;

            }
            finally
            {
                conn.Close();
            }

            return loanPayDetails;
        }