private void sell() { //throw new NotImplementedException(); try { if (textBoxTotalAmount.Text != "" && textBoxBalance.Text != "" && textBoxCash.Text != "" || textBox2.Text != "") { getreceiptno(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value != null) { //float available = 0,totalqty; available = Convert.ToInt32(textBox1.Text); //sold = Convert.ToInt32(textBoxQuantity.Text); totalqty = available - qty; getCreditno(); sqlconnectionclass getstatus = new sqlconnectionclass(); DR = getstatus.ReadDB("select count(*) from stockin where productno='" + row.Cells[0].Value + "'"); if (DR.HasRows) { DR.Read(); if (Convert.ToInt32(DR[0]) > 0) { status = 0; } else { status = 1; } } string insertsale = "INSERT INTO [Sales]([ProductNo],[sqty],[sprice],[totalcost],[VAT],[credit_customerID],[credit_no],[unknown],[receiptno],[date])VALUES('" + row.Cells[0].Value + "','" + row.Cells[3].Value + "','" + row.Cells[2].Value + "','" + row.Cells[5].Value + "','" + row.Cells[4].Value + "','" + cust_id + "','" + nextcreditno + "','" + status + "','" + ReceiptNo + "','" + System.DateTime.Now + "')"; new sqlconnectionclass().WriteDB(insertsale); string insertstockcard = "INSERT INTO [Stockcard]([ProductNo] ,[Transaction_Date],[Naration] ,[Qty_in] ,[Qty_out],[Lacation],[System_User],[New_Stock],[Available_Stock],[DateReport],[Timereport]) VALUES('" + row.Cells[0].Value + "','" + System.DateTime.Now + "','Sale of ''" + productname + "','" + '0' + "','" + row.Cells[3].Value + "','Store','" + Form1.UserName + "','" + totalqty + "','" + textBox1.Text + "','" + System.DateTime.Now + "','" + System.DateTime.Now + "')"; new sqlconnectionclass().WriteDB(insertstockcard); if (radioButton2.Checked == true) { string insertcredit = "INSERT INTO credit_sales([credit_no],[credit_customerID],[amount],[description],[user],[date])values('" + nextcreditno + "','" + cust_id + "','" + txtcreditsales.Text + "','being sales of''" + productname + "','" + Form1.UserName + "','" + System.DateTime.Now.ToShortDateString() + "')"; new sqlconnectionclass().WriteDB(insertcredit); creditbalance(); totalbal = Convert.ToInt32(txtcreditsales.Text); bal2 = bal + totalbal; string insertgledger = "INSERT INTO [GLedger]([credit_customerID],[Debit],[Balance],[Date],[user],[Naration])values('" + cust_id + "','" + txtcreditsales.Text + "','" + bal2 + "','" + System.DateTime.Now + "','" + Form1.UserName + "','Being sales of''" + productname + "')"; new sqlconnectionclass().WriteDB(insertgledger); } } } //if(){} /*****======================Begin Print=====================*****/ PrinterUtility.EscPosEpsonCommands.EscPosEpson obj = new PrinterUtility.EscPosEpsonCommands.EscPosEpson(); var BytesValue = Encoding.ASCII.GetBytes(string.Empty); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.DoubleWidth2()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); //BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("JOMAT GENERAL HARDWARE\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.Nomarl()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Dealers in: Hardware e.g Iron sheets, Cement,\n Plywood, Paints, Glassmart, Supply of general\nbuilding materials etc.\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("P.O. BOX 4, NGONG\nNGONG RD-KISERIAN, MATASIA SHOPPING CENTRE\nTEL: 0721-283-402/0724-477-792\nKRA PIN.:A001204489T \n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.Nomarl()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("RECEIPT\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Left()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Receipt No : " + ReceiptNo + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Date : " + System.DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture) + "\n")); //BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("PIN. :A001204489T \n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Right()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(" Item Qty U. Price VAT Total\n")); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(" Name KES KES KES\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); foreach (DataGridViewRow dgv in dataGridView1.Rows) { BytesValue = PrintExtensions.AddBytes(BytesValue, string.Format("{0,-19}{1,9}{2,9}{3,10}{4,16:N2}\n", dgv.Cells[1].Value, dgv.Cells[3].Value, dgv.Cells[2].Value, dgv.Cells[4].Value, dgv.Cells[5].Value)); } //BytesValue = PrintExtensions.AddBytes(BytesValue, string.Format("{0,-40}{1,6}{2,9}{3,9:N2}\n", "item 1", 12, 11, 144.00)); //BytesValue = PrintExtensions.AddBytes(BytesValue, string.Format("{0,-40}{1,6}{2,9}{3,9:N2}\n", "item 2", 12, 11, 144.00)); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Right()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Total: ")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(textBoxTotalAmount.Text + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Cash: ")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(textBoxCash.Text + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Change: ")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(textBoxBalance.Text + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.DoubleWidth2()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Mpesa Till No 524049\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.Nomarl()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Lf()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.BarCode.Code128("12345")); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.QrCode.Print("12345", PrinterUtility.Enums.QrCodeSize.Grande)); BytesValue = PrintExtensions.AddBytes(BytesValue, "Goods Once sold cannot be returned\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, "You're served by " + Form1.UserName + "\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, "Designed by Amtech Technologies\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, "Website: www.amtechafrica.com Email: [email protected]\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, "------Thank you for shopping with us-------\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Left()); BytesValue = PrintExtensions.AddBytes(BytesValue, CutPage()); //PrinterUtility.PrintExtensions.Print(BytesValue, EasyPOS.Properties.Settings.Default.printerpath); if (File.Exists(".\\tmpPrint.print")) { File.Delete(".\\tmpPrint.print"); } File.WriteAllBytes(".\\tmpPrint.print", BytesValue); RawPrinterHelper.SendFileToPrinter("Generic / Text Only", ".\\tmpPrint.print"); try { File.Delete(".\\tmpPrint.print"); } catch { } /******END PRINT & Begin collection**********/ PrinterUtility.EscPosEpsonCommands.EscPosEpson obj1 = new PrinterUtility.EscPosEpsonCommands.EscPosEpson(); var BytesValue1 = Encoding.ASCII.GetBytes(string.Empty); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.CharSize.DoubleWidth2()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.FontSelect.FontA()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Alignment.Center()); //BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("\n")); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes("JOMAT GENERAL HARDWARE\n")); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.CharSize.Nomarl()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes("Collection RECEIPT\n")); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.CharSize.Nomarl()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Alignment.Right()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes("Receipt No : " + ReceiptNo + "\n")); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes("Date: " + System.DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture) + "\n")); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Left()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes(" Item Qty U. Price VAT Total\n")); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); BytesValue = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes(" Name KES KES KES\n")); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Separator()); foreach (DataGridViewRow dgv in dataGridView1.Rows) { BytesValue1 = PrintExtensions.AddBytes(BytesValue1, string.Format("{0,-19}{1,9}{2,9}{3,10}{4,16:N2}\n", dgv.Cells[1].Value, dgv.Cells[3].Value, dgv.Cells[2].Value, dgv.Cells[4].Value, dgv.Cells[5].Value)); } BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Alignment.Right()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Separator()); //BytesValue1 = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes("Total: ")); //BytesValue1 = PrintExtensions.AddBytes(BytesValue1, Encoding.ASCII.GetBytes(textBoxTotalAmount.Text + "\n")); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj.Lf()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, "Signed:.............................................\n"); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Alignment.Center()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, "You're served by " + Form1.UserName + "\n"); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj.Separator()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, "Designed by Amtech Technologies\n"); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, "Website: www.amtechafrica.com Email: [email protected]\n"); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, obj1.Alignment.Left()); BytesValue1 = PrintExtensions.AddBytes(BytesValue1, CutPage()); if (File.Exists(".\\tmpPrint1.print")) { File.Delete(".\\tmpPrint1.print"); } File.WriteAllBytes(".\\tmpPrint1.print", BytesValue1); RawPrinterHelper.SendFileToPrinter("Generic / Text Only", ".\\tmpPrint1.print"); try { File.Delete(".\\tmpPrint1.print"); } catch { } /*********END collector copy****************/ textBoxTotalAmount.Text = "0"; textBoxCash.Text = "0"; textBoxBalance.Text = "0"; } else { MessageBox.Show("Enter Cash Amount"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void buttonPay_Click(object sender, EventArgs e) { string paymode = ""; if (radioButton1.Checked == true) { paymode = "Cash"; } else if (radioButton2.Checked == true) { paymode = "Cheque"; } string pay = "INSERT INTO [creditPayment]([credit_customerID],[BussinessName],[paymentmode],[amount],[balance],[description],[chequeno],[datepay],[duedate],[date],[user])VALUES('" + pid + "','" + cmbBusinessname.Text + "','" + paymode + "','" + textBoxAmount.Text + "','" + txtRemaining.Text + "','Payment of Credit','" + textBoxChequeNo.Text + "','" + datePay.Text + "','" + Duedate.Text + "','" + System.DateTime.Now + "','" + Form1.UserName + "')"; new sqlconnectionclass().WriteDB(pay); string gledger = "INSERT INTO [GLedger]([credit_customerID],[Credit],[Balance],[Date],[user],[Naration])VALUES('" + pid + "','" + textBoxAmount.Text + "','" + txtRemaining.Text + "','" + System.DateTime.Now + "','" + Form1.UserName + "','Credit Payment')"; new sqlconnectionclass().WriteDB(gledger); MessageBox.Show("success"); /*****======================Begin Print=====================*****/ PrinterUtility.EscPosEpsonCommands.EscPosEpson obj = new PrinterUtility.EscPosEpsonCommands.EscPosEpson(); var BytesValue = Encoding.ASCII.GetBytes(string.Empty); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.DoubleWidth2()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); //BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("JOMAT GENERAL HARDWARE\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.Nomarl()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Dealers in: Hardware e.g Iron sheets, Cement,\n Plywood, Paints, Glassmart, Supply of general\nbuilding materials etc.\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("P.O. BOX 4, NGONG\nNGONG RD-KISERIAN, MATASIA SHOPPING CENTRE\nTEL: 0721-283-402/0724-477-792\nKRA PIN.:A001204489T \n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.Nomarl()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("CREDIT PAYMENT RECEIPT\n")); // BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Left()); // BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Receipt No : " + ReceiptNo + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Date : " + System.DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture) + "\n")); //BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("PIN. :A001204489T \n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Right()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(" MEMBER NAME TOTAL Balance CASH Paid REMAINING\n")); ////BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(" Name KES KES KES\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); //foreach (DataGridViewRow dgv in dataGridView1.Rows) //{ BytesValue = PrintExtensions.AddBytes(BytesValue, string.Format("{0,19}{1,9}{2,10}{3,16:N2}\n", cmbBusinessname.Text, balancetxt.Text, textBoxAmount.Text, txtRemaining.Text)); //} //BytesValue = PrintExtensions.AddBytes(BytesValue, string.Format("{0,-40}{1,6}{2,9}{3,9:N2}\n", "item 1", 12, 11, 144.00)); //BytesValue = PrintExtensions.AddBytes(BytesValue, string.Format("{0,-40}{1,6}{2,9}{3,9:N2}\n", "item 2", 12, 11, 144.00)); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Right()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Total Balance: ")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(balancetxt.Text + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Cash: ")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(textBoxAmount.Text + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Remaining: ")); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes(txtRemaining.Text + "\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.DoubleWidth2()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); BytesValue = PrintExtensions.AddBytes(BytesValue, Encoding.ASCII.GetBytes("Mpesa Till No 524049\n")); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.CharSize.Nomarl()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.FontSelect.FontA()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Lf()); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Center()); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.BarCode.Code128("12345")); //BytesValue = PrintExtensions.AddBytes(BytesValue, obj.QrCode.Print("12345", PrinterUtility.Enums.QrCodeSize.Grande)); // BytesValue = PrintExtensions.AddBytes(BytesValue, "Goods Once sold cannot be returned\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, "You're served by " + Form1.UserName + "\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Separator()); BytesValue = PrintExtensions.AddBytes(BytesValue, "Designed by Amtech Technologies\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, "Website: www.amtechafrica.com Email: [email protected]\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, "------Thank you for shopping with us-------\n"); BytesValue = PrintExtensions.AddBytes(BytesValue, obj.Alignment.Left()); BytesValue = PrintExtensions.AddBytes(BytesValue, CutPage()); //PrinterUtility.PrintExtensions.Print(BytesValue, EasyPOS.Properties.Settings.Default.printerpath); if (File.Exists(".\\tmpPrint.print")) { File.Delete(".\\tmpPrint.print"); } File.WriteAllBytes(".\\tmpPrint.print", BytesValue); RawPrinterHelper.SendFileToPrinter("Generic / Text Only", ".\\tmpPrint.print"); try { File.Delete(".\\tmpPrint.print"); } catch { } }