Ejemplo n.º 1
0
 private void btnprtInvoice_Click(object sender, EventArgs e)
 {
     Statement.frmInvoiceReport rpt = new frmInvoiceReport();
     rpt.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
     int numVal = Int32.Parse(Id);
     rpt.InvoiceId = numVal;
     rpt.ShowDialog();
 }
Ejemplo n.º 2
0
        private void btnsave_Click(object sender, EventArgs e)
        {
            if (txtDiscount.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนยอดหักส่วนลด", "ตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtDiscount.Focus();
                return;
            }
            if (MessageBox.Show("คุณต้องการบันทึกรายการสเตทเม้นท์  " + txtnameCustomer.Text.Trim() + " ใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {

                tr = Conn.BeginTransaction();
                try
                {
                    string sqlSaveStHead;
                    sb = new StringBuilder();
                    sb.Remove(0, sb.Length);
                    sb.Append("INSERT INTO STATEMENT_HEAD ");
                    sb.Append("(StatementHeadId, CustomerId, StatementReceiveMoney, StatementHeadDatetime, MoneyDiscount, BankAccountId,Bank_Charges, UserName, InvoiceNumber, RINumber, Remark ) ");
                    sb.Append("VALUES ");
                    sb.Append("(@StatementHeadId, @CustomerId, @StatementReceiveMoney, @StatementHeadDatetime, @MoneyDiscount, @BankAccountId,@Bank_Charges, @UserName, @InvoiceNumber, @RINumber, @Remark )");

                    sqlSaveStHead = sb.ToString();

                    Com.Parameters.Clear();
                    Com.Transaction = tr;
                    Com.CommandText = sqlSaveStHead;
                    Com.Parameters.Add("@StatementHeadId", SqlDbType.Int).Value = HeadId;
                    Com.Parameters.Add("@CustomerId", SqlDbType.Int).Value = txtidCustomer.Text.Trim();
                    Com.Parameters.Add("@StatementReceiveMoney", SqlDbType.Decimal).Value = Convert.ToDecimal(txtNet.Text.Trim());
                    Com.Parameters.Add("@StatementHeadDatetime", SqlDbType.DateTime).Value = dtpReceiveDate.Value.ToString("dd/MM/yyyy HH:mm:ss");
                    Com.Parameters.Add("@MoneyDiscount", SqlDbType.Decimal).Value = Convert.ToDecimal(txtDiscount.Text.Trim());
                    Com.Parameters.Add("@BankAccountId", SqlDbType.Int).Value = COMBO_BANK.SelectedValue.ToString();
                    Com.Parameters.Add("@Bank_Charges", SqlDbType.Decimal).Value = Convert.ToDecimal(txtBank_Charges.Text.Trim());
                    Com.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = UserName;
                    Com.Parameters.Add("@InvoiceNumber", SqlDbType.NVarChar).Value = txtInvoiceNumber.Text.Trim();
                    Com.Parameters.Add("@RINumber", SqlDbType.NVarChar).Value = txtHandId.Text.Trim();
                    Com.Parameters.Add("@Remark", SqlDbType.NVarChar).Value = txtRemark.Text.Trim();
                    Com.ExecuteNonQuery();

                    for (int i = 0; i <= dgvDetailStatement.Rows.Count - 1; i++)
                    {
                        sb.Remove(0, sb.Length);
                        sb.Append("INSERT INTO STATEMENT_DETAIL ");
                        sb.Append("(StatementHeadId, SaleHeadId, moneyPay , Deposit_Pay ,Bill) ");
                        sb.Append("VALUES ");
                        sb.Append("(@StatementHeadId, @SaleHeadId, @moneyPay , @Deposit_Pay ,@Bill ) ");

                        if (dgvDetailStatement.Rows[i].Cells[6].Value.ToString() == "0.00")
                        {
                            sb.Append("UPDATE SETDEBT SET StatusDebtId = 2 WHERE SaleHeadId = @SaleHeadId ");
                            //sb.Append("UPDATE OLD_SETDEBT SET StatusDebtId = 2 WHERE Bill = @SaleHeadId AND CustomerId = @CustomerId ");
                        }
                        if (dgvDetailStatement.Rows[i].Cells[6].Value.ToString() != "0.00")
                        {
                            sb.Append("UPDATE SETDEBT SET StatusDebtId = 1 WHERE SaleHeadId = @SaleHeadId");
                            //sb.Append("UPDATE OLD_SETDEBT SET StatusDebtId = 1 WHERE Bill = @SaleHeadId");
                        }
                        sb.Append(" UPDATE SALE_HEAD SET Deposit_Status = 1 WHERE SaleHeadId = @SaleHeadId");
                        //sb.Append(" UPDATE SALE_HEAD SET Deposit_Pay = 0 WHERE SaleHeadId = @SaleHeadId");

                        sqlSaveStHead = sb.ToString();

                        Com.Parameters.Clear();
                        Com.CommandText = sqlSaveStHead;
                        Com.Parameters.Add("@StatementHeadId", SqlDbType.Int).Value = HeadId;
                        Com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = dgvDetailStatement.Rows[i].Cells[0].Value.ToString();
                        Com.Parameters.Add("@moneyPay", SqlDbType.Decimal).Value = Convert.ToDecimal(dgvDetailStatement.Rows[i].Cells[5].Value.ToString());
                        Com.Parameters.Add("@Deposit_Pay", SqlDbType.Decimal).Value = Convert.ToDecimal(dgvDetailStatement.Rows[i].Cells[4].Value.ToString());
                        Com.Parameters.Add("@Bill", SqlDbType.Decimal).Value = Convert.ToDecimal(dgvDetailStatement.Rows[i].Cells[6].Value.ToString());
                        Com.Parameters.Add("@CustomerId", SqlDbType.Int).Value = txtidCustomer.Text.Trim();
                        Com.ExecuteNonQuery();
                    }

                    MessageBox.Show("บันทึกรายการรายการสเตทเม้นท์เรียบร้อยแล้ว!!!", "ผลการยืนยัน", MessageBoxButtons.OK, MessageBoxIcon.None);
                    tr.Commit();

                    DialogResult dlg = MessageBox.Show("ต้องการพิมพ์ใบเสร็จรับเงินหรือไม่!!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dlg == DialogResult.OK)
                    {

                        Statement.frmInvoiceReport rpt = new frmInvoiceReport();
                        rpt.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
                        rpt.InvoiceId = HeadId;
                        rpt.ShowDialog();

                    }
                    MaxStatementIndex();
                    ClearAfterSave();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ไม่สามารถบันทึกรายการสเตทเม้นท์ได้ เนื่องจาก " + ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    tr.Rollback();
                }
            }
        }