public void DeleteInvoiceHeaderFromDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 10
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            invoiceDao = new InvoiceDao(_sqlConnection);

            var rowsAffected = invoiceDao.Delete(invoiceHeader);

            Assert.IsTrue(rowsAffected == 1);
        }
        public void GetInvoiceHeaderEntityByInvoiceNumberFromDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 56
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceHeader = invoiceDao.GetByInvoiceNumber(invoiceHeader.InvoiceNumber);

            Assert.IsTrue(invoiceHeader != null);
        }
示例#3
0
        private bool saveData()
        {
            try
            {
                setRef1();
                validateData();
                bool isNew = false;

                InvoiceObj obj = new InvoiceDao().find(this.invoiceID);
                if (obj == null)
                {
                    obj           = new InvoiceObj();
                    obj.invoiceId = this.invoiceID;
                    isNew         = true;
                }
                if (is_replace.IsChecked.Value)
                {
                    obj.purpose     = purposeCbb.Text;
                    obj.issueDate   = docDateTb.Text;
                    obj.purposeCode = purposeCbb.SelectedValue.ToString();
                    if (purposeCbb.SelectedValue.ToString() == "TIVC99")
                    {
                        obj.purpose = otherPurposeTb.Text;
                    }
                    else
                    {
                        obj.purpose = purposeCbb.Text;
                    }
                }
                else
                {
                    obj.issueDate = DateTime.Now.ToString("dd/MM/yyyy", new CultureInfo("en-US"));
                }
                obj.invoiceName         = "ใบกำกับภาษี";
                obj.taxCode             = "VAT";
                obj.taxRate             = Convert.ToDouble(vatTb.Text);
                obj.basisAmount         = Convert.ToDouble(basisAmountTb.Text);
                obj.lineTotal           = Convert.ToDouble(lineTotalTb.Text);
                obj.discount            = Convert.ToDouble(extraDiscountTb.Text);
                obj.discount_rate       = Convert.ToDouble(extraDiscountRateTb.Text);
                obj.taxTotal            = Convert.ToDouble(taxTotalTb.Text);
                obj.grandTotal          = Convert.ToDouble(grandTotalTb.Text);
                obj.service_charge      = Convert.ToDouble(serviceChargeTb.Text);
                obj.service_charge_rate = Convert.ToDouble(serviceChargeRateTb.Text);
                //obj.issueDate = DateTime.Now.ToString();
                obj.remark = remarkTb.Text;

                BuyerObj buyer = (BuyerObj)nameCbb.SelectedItem;
                if (buyer == null)
                {
                    buyer = new BuyerObj();
                }
                buyer.name     = nameCbb.Text;
                buyer.address1 = address1Tb.Text;
                buyer.houseNo  = houseNoTb.Text;
                buyer.zipCode  = zipcodeTb.Text;
                buyer.taxId    = taxIdTb.Text;
                if (is_branch.IsChecked.Value)
                {
                    buyer.isBranch = true;
                    buyer.branchId = branchNoTb.Text;
                }
                else
                {
                    buyer.isBranch = false;
                    buyer.branchId = "00000";
                }
                buyer.email         = emailTb.Text;
                buyer.contactPerson = contactTb.Text;
                buyer.phoneNo       = phoneNoTb.Text;
                buyer.phoneExt      = phoneExtTb.Text;

                buyer.provinceCode    = ((AddressCodeListObj)provinceCbb.SelectedItem).code.Substring(0, 2);
                buyer.provinceName    = ((AddressCodeListObj)provinceCbb.SelectedItem).changwat_th;
                buyer.districtCode    = ((AddressCodeListObj)amphoeCbb.SelectedItem).code.Substring(0, 4);
                buyer.districtName    = ((AddressCodeListObj)amphoeCbb.SelectedItem).amphoe_th;
                buyer.subdistrcitCode = ((AddressCodeListObj)tambonCbb.SelectedItem).code.Substring(0, 6);
                buyer.subdistrictName = ((AddressCodeListObj)tambonCbb.SelectedItem).tambon_th;

                obj.sellerId = saveContact(seller);
                obj.buyerId  = saveContact(buyer);
                saveReferece();
                saveInvoiceItem();
                new InvoiceDao().save(obj, isNew);
                return(true);
            }
            catch (Exception ex)
            {
                createBtn.IsEnabled = true;
                new AlertBox(ex.Message).ShowDialog();
                return(false);
            }
        }
        public void GetInvoiceHeaderEntityBySqlFromDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 56
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            invoiceDao = new InvoiceDao(_sqlConnection);

            string sqlQuery = $"SELECT * FROM InvoiceHeader WHERE [Id] = {invoiceHeader.Id}";

            invoiceHeader = invoiceDao.GetBySql(sqlQuery);

            Assert.IsTrue(invoiceHeader != null);
        }
        public void WriteInvoiceHeaderEntityToDatabase()
        {
            IInvoice invoiceHeader = new Invoice
            {
                CustomerId = 1,
                SupplierId = 2,
                InvoiceNumber = 10
            };

            IInvoiceDao invoiceDao = new InvoiceDao(_sqlConnection);

            invoiceDao.Write(invoiceHeader);

            Assert.IsTrue(invoiceHeader.Id > 0);
        }