private void btnSaveBill_Click(object sender, EventArgs e) { dgvSell.Columns[0].Visible = false; tbSellProductID.Enabled = false; BillOrder billOrder = new BillOrder(); billOrder.CustomerID = tbSellCustomerID.Text.Trim(); billOrder.CustomerName = tbSellCustomerName.Text.Trim(); billOrder.EmployeeName = tbSellSeller.Text.Trim(); int iDay = dtpSellDate.Value.Day; int iMonth = dtpSellDate.Value.Month; int iYear = dtpSellDate.Value.Year; if (CultureInfo.CurrentCulture.ToString() == "th-TH") { iYear = iYear + 543; } billOrder.SellDate = MyPrint16.makeDateTransaction(iDay, iMonth, iYear); billOrder.BillNumber = int.Parse(tbSellNoBill.Text.ToString()); for (int i = 0; i < dgvSell.Rows.Count; i++) { billOrder.ProductID = dgvSell.Rows[i].Cells[1].Value.ToString(); billOrder.ProductName = dgvSell.Rows[i].Cells[2].Value.ToString(); billOrder.Amount = int.Parse(dgvSell.Rows[i].Cells[4].Value.ToString()); billOrder.Discount = double.Parse(dgvSell.Rows[i].Cells[5].Value.ToString()); billOrder.TotalPrice = double.Parse(dgvSell.Rows[i].Cells[6].Value.ToString()); insertToBills(billOrder); } btnNewBill.Visible = true; btnSellCancel.Visible = false; increaseCirculation(double.Parse(tbTotalPrice.Text), billOrder.SellDate); btnDeleteOrder.Enabled = false; btnSaveBill.Enabled = false; }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { printDocument1 = new PrintDocument(); Font fnt = new Font("Tahoma", 20); Point pDoll2U = new Point(350, 50); Point pBillNumber = new Point(650, 50); Point pBillText = new Point(320, 100); Point pDate = new Point(20, 130); Point pBranch = new Point(600, 130); Point pCustomerID = new Point(20, 160); Point pCustomerName = new Point(550, 160); Point pEmployee = new Point(20, 190); Point pProductHead = new Point(20, 250); string strStoreName = "Doll2U"; string strBillNumber = "เลขที่: " + NumberFormat.getStringNumber(int.Parse(tbSellNoBill.Text)); string strBillText = "ใบเสร็จรับเงิน"; string strDate = "วันที่ "; if (dtpSellDate.Visible == true) { int iCurrentDay = dtpSellDate.Value.Day; int iCurrentMonth = dtpSellDate.Value.Month; int iCurrentYear = dtpSellDate.Value.Year; strDate = strDate + MyPrint16.makeDatePrint(iCurrentDay, iCurrentMonth, iCurrentYear); } else { strDate = strDate + tbDatePastBill.Text.Trim(); } string strBranch = "สาขา สยามสแควร์"; string strCustomerID = "รหัสลูกค้า " + tbSellCustomerID.Text.Trim(); string strCustomerName = "ชื่อลูกค้า " + tbSellCustomerName.Text.Trim(); string strEmployee = "พนักงาน: " + tbSellSeller.Text.Trim(); string strProductHead = "รหัสสินค้า ชื่อสินค้า จำนวน ราคา(บาท)"; e.Graphics.DrawString(strStoreName, fnt, Brushes.Black, pDoll2U); e.Graphics.DrawString(strBillNumber, fnt, Brushes.Black, pBillNumber); e.Graphics.DrawString(strBillText, fnt, Brushes.Black, pBillText); fnt = new Font("Tahoma", 16); e.Graphics.DrawString(strDate, fnt, Brushes.Black, pDate); e.Graphics.DrawString(strBranch, fnt, Brushes.Black, pBranch); e.Graphics.DrawString(strCustomerID, fnt, Brushes.Black, pCustomerID); e.Graphics.DrawString(strCustomerName, fnt, Brushes.Black, pCustomerName); e.Graphics.DrawString(strEmployee, fnt, Brushes.Black, pEmployee); e.Graphics.DrawString(strProductHead, fnt, Brushes.Black, pProductHead); int yTarget = 250 + fnt.Height; double dbSumDiscount = 0.0d; double dbSumPrice = 0.0d; //พิมพ์รายการสินค้าใน Bill for (int i = 0; i < dgvSell.Rows.Count; i++) { //พิมพ์รหัสสินค้า e.Graphics.DrawString(dgvSell.Rows[i].Cells[1].Value.ToString(), fnt, Brushes.Black, 20, yTarget); //พิมพ์ชื่อสินค้า e.Graphics.DrawString(dgvSell.Rows[i].Cells[2].Value.ToString(), fnt, Brushes.Black, 120, yTarget); //พิมพ์จำนวน int iAmountEach = int.Parse(dgvSell.Rows[i].Cells[4].Value.ToString()); int iXAmountEach = MyPrint16.getXNumber(558, iAmountEach); string strAmountEach = NumberFormat.getStringNumber(iAmountEach); e.Graphics.DrawString(strAmountEach, fnt, Brushes.Black, iXAmountEach, yTarget); //พิมพ์ราคา double dbDiscount = double.Parse(dgvSell.Rows[i].Cells[5].Value.ToString()); dbSumDiscount = dbSumDiscount + dbDiscount; double dbPriceAfterDiscount = double.Parse(dgvSell.Rows[i].Cells[6].Value.ToString()); double dbPrice = dbPriceAfterDiscount + dbDiscount; dbSumPrice = dbSumPrice + dbPrice; int iXdbPrice = MyPrint16.getXCurrency(730, dbPrice); string strPrice = NumberFormat.getStringCurrency(dbPrice); e.Graphics.DrawString(strPrice, fnt, Brushes.Black, iXdbPrice, yTarget); yTarget = yTarget + fnt.Height; } yTarget = 880; //พิมพ์ ราคารวม e.Graphics.DrawString("ราคารวม", fnt, Brushes.Black, 20, yTarget); int iXdbSumPrice = MyPrint16.getXCurrency(730, dbSumPrice); string strSumPrice = NumberFormat.getStringCurrency(dbSumPrice); e.Graphics.DrawString(strSumPrice, fnt, Brushes.Black, iXdbSumPrice, yTarget); if (dbSumDiscount > 0.0) { //รวมส่วนลด yTarget = yTarget + fnt.Height; e.Graphics.DrawString("รวมส่วนลด", fnt, Brushes.Black, 20, yTarget); int iXBeginSumDiscount = MyPrint16.getXCurrency(723, dbSumDiscount); string strSumDiscount = NumberFormat.getStringCurrency(dbSumDiscount); e.Graphics.DrawString("-" + strSumDiscount, fnt, Brushes.Black, iXBeginSumDiscount, yTarget); } //พิมพ์ราคาหลังหักส่วนลด yTarget = yTarget + fnt.Height; e.Graphics.DrawString("ราคาหลังหักส่วนลด", fnt, Brushes.Black, 20, yTarget); double dbPriceComplete = double.Parse(tbTotalPrice.Text.Trim()); string strPriceTotal = NumberFormat.getStringCurrency(dbPriceComplete); int iXBeginPriceComplete = MyPrint16.getXCurrency(730, dbPriceComplete); e.Graphics.DrawString(strPriceTotal, fnt, Brushes.Black, iXBeginPriceComplete, yTarget); //พิมพ์ภาษีมูลค่าเพิ่ม yTarget = yTarget + fnt.Height; e.Graphics.DrawString("ภาษีมูลค่าเพิ่ม 7%", fnt, Brushes.Black, 20, yTarget); double dbPriceVAT = dbPriceComplete * 7 / 107; string strPriceVAT = NumberFormat.getStringCurrency(dbPriceVAT); int iXBeginPriceVAT = MyPrint16.getXCurrency(730, dbPriceVAT); e.Graphics.DrawString(strPriceVAT, fnt, Brushes.Black, iXBeginPriceVAT, yTarget); //พิมพ์ราคาสุทธิ yTarget = yTarget + fnt.Height; e.Graphics.DrawString("ราคาสุทธิ", fnt, Brushes.Black, 20, yTarget); e.Graphics.DrawString(strPriceTotal, fnt, Brushes.Black, iXBeginPriceComplete, yTarget); //พิมพ์ Include VAT e.Graphics.DrawString("Include VAT", fnt, Brushes.Black, 320, 1050); //พิมพ์ขอบคุณที่ใช้บริการ e.Graphics.DrawString("ขอบคุณที่ใช้บริการ", fnt, Brushes.Black, 300, 1050 + fnt.Height); }
private void showDetailPastBill(int iPastBillNumbet) { dgvSell.Rows.Clear(); dgvSell.Columns[0].Visible = false; StringBuilder sb = new StringBuilder(); sb.Append("SELECT FORMAT(SellDate,'dd/MM/yyyy') AS SellDate,EmployeeName,CustomerID,CustomerName,ProductID,ProductName,Amount,Discount,TotalPrice"); sb.Append(" FROM Bills"); sb.Append(" WHERE BillNumber=@BillNumber"); string sqlSelect = sb.ToString(); OpenConnection(); OleDbCommand com = new OleDbCommand(); com.CommandType = CommandType.Text; com.CommandText = sqlSelect; com.Connection = Conn; com.Parameters.Add("@BillNumber", OleDbType.BigInt).Value = tbSearchBill.Text.Trim(); try { OleDbDataReader dr = com.ExecuteReader(); if (dr.HasRows == true) { DataTable dt = new DataTable(); dt.Load(dr); tbSellCustomerID.ReadOnly = true; tbSellCustomerID.Text = dt.Rows[0]["CustomerID"].ToString(); tbSellCustomerName.Enabled = true; tbSellCustomerName.Text = dt.Rows[0]["CustomerName"].ToString(); tbSellSeller.Enabled = true; tbSellSeller.ReadOnly = true; tbSellSeller.Text = dt.Rows[0]["EmployeeName"].ToString(); dtpSellDate.Visible = false; tbDatePastBill.Visible = true; string strPastDate = dt.Rows[0]["SellDate"].ToString(); int iPastDay = MyPrint16.getDayFromTextDate(strPastDate); int iPastMonth = MyPrint16.getMonthFromTextDate(strPastDate); int iPastYear = MyPrint16.getYearFromTextDate(strPastDate); if (CultureInfo.CurrentCulture.ToString() == "th-TH") { iPastYear = iPastYear - 543; } tbDatePastBill.Text = MyPrint16.makeDatePrint(iPastDay, iPastMonth, iPastYear); tbSellNoBill.Enabled = true; tbSellNoBill.ReadOnly = true; tbSellNoBill.Text = tbSearchBill.Text; dgvSell.Enabled = true; double dbSumPrice = 0.0d; for (int i = 0; i < dt.Rows.Count; i++) { dgvSell.Rows.Add(); int iIndex = dgvSell.Rows.Count - 1; dgvSell.Rows[iIndex].Cells[0].Value = false; dgvSell.Rows[iIndex].Cells[1].Value = dt.Rows[i]["ProductID"].ToString(); dgvSell.Rows[iIndex].Cells[2].Value = dt.Rows[i]["ProductName"].ToString(); int iAmount = int.Parse(dt.Rows[i]["Amount"].ToString()); double dbDiscount = double.Parse(dt.Rows[i]["Discount"].ToString()); double dbTotalPrice = double.Parse(dt.Rows[i]["TotalPrice"].ToString()); dbSumPrice = dbSumPrice + dbTotalPrice; double dbPricePerUnit = (dbTotalPrice + dbDiscount) / (double)iAmount; dgvSell.Rows[iIndex].Cells[3].Value = NumberFormat.getStringCurrency(dbPricePerUnit); dgvSell.Rows[iIndex].Cells[4].Value = iAmount.ToString(); dgvSell.Rows[iIndex].Cells[5].Value = NumberFormat.getStringCurrency(dbDiscount); dgvSell.Rows[iIndex].Cells[6].Value = NumberFormat.getStringCurrency(dbTotalPrice); } tbTotalPrice.Enabled = true; tbTotalPrice.Text = NumberFormat.getStringCurrency(dbSumPrice); btnSellPrint.Enabled = true; btnNewBill.Visible = true; btnSellCancel.Visible = false; } else { clearForNewBill(); btnNewBill.Visible = false; btnSellCancel.Visible = true; MessageBox.Show("ไม่พบใบเสร็จที่ตรงกับเลขที่ใบเสร็จนี้ค่ะ", cstWarning); } CloseConnection(); } catch (Exception ex) { CloseConnection(); MessageBox.Show(ex.Message, cstWarning); } }