private void radButton1_Click(object sender, EventArgs e) { GlobleAccess.invoiceNo = cmb_InvoiceNo.Text; if (txtPaymentNo.Text == "") { MessageBox.Show("Please Check Payment No !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else if (cmb_InvoiceNo.Text == "") { MessageBox.Show("Please select a invoice !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else if (txtCusName.Text == "" || txtCusNo.Text == "") { MessageBox.Show("Please select customer !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else if (txtAmount.Text.Trim() == "") { MessageBox.Show("Please add the payment amount", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else if (radCashPayment.Checked == true) { string paymentNo = txtPaymentNo.Text.ToString(); string cusNo = txtCusNo.Text.ToString(); string customerName = txtCusName.Text.ToString(); string date = dtpPaymentDate.Value.Date.ToString("yyyy-MM-dd") + " " + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString(); string payAmount = txtAmount.Text.ToString(); string q1 = "INSERT INTO payments(paymentno, customer, amount,paymentdate,invoiceno) VALUES('" + paymentNo + "','" + cusNo + "', '" + payAmount + "','" + date + "','" + cmb_InvoiceNo.Text + "')"; bool status1 = middle_access.db_access.InsertData(q1); bool status2 = true; if (chkCreditCardPayment.Checked) { if (txtCardNo.Text == "") { MessageBox.Show("Please enter credit card no !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else if (txtReciptNo.Text == "") { MessageBox.Show("Please enter recipt no !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else if (cmdCardType.Text.ToString() == "") MessageBox.Show("Please select credit card type !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); else { // isCreditCardPayment = "1"; string receiptNo = txtReciptNo.Text.ToString(); string creditCardNo = txtCardNo.Text.ToString(); string cardType = cmdCardType.SelectedItem.ToString(); string creditNote = txtCreditNote.Text.ToString(); string expireDate = dtpExpDate.Value.Date.ToString("yyyy-MM-dd"); string q2 = "INSERT INTO creditcard (reciptNo, paymentNo, cardNo, cardType,expireDate,note) VALUES ('" + receiptNo + "', '" + paymentNo + "', '" + creditCardNo + "', '" + cardType + "', '" + expireDate + "','" + creditNote + "')"; status2 = middle_access.db_access.InsertData(q2); } } else { //isCreditCardPayment = "0"; } if (status1 == true && status2 == true) // if data is insert { //if (GlobleAccess.openType == "M") //{ insertAccountDetaila(); //} MessageBox.Show("Cash Payment successfully added !"); Clear(); autoIncrement(); if (GlobleAccess.openType != "I") { Insert_Data_To_temp_invoice_print(); } // CurrentInvoicePrint.paymenCount = GlobleAccess.Get_Payments_Sum(); CurrentInvoicePrint ci = new CurrentInvoicePrint(); ci.Show(); } else { MessageBox.Show("Error : Payment not added !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } ///////////////////////////// } else if (radChequePayment.Checked == true) { if (txtChequeNo.Text == "") { MessageBox.Show("Add Cheque No !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else if (cmbBank.Text == "") { MessageBox.Show("Select a Bank !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { if (chkIsCashCheque.Checked) { isCashCheque = "1"; } else { isCashCheque = "0"; } string paymentNo = txtPaymentNo.Text.ToString(); string cusNo = txtCusNo.Text.ToString(); string customerName = txtCusName.Text.ToString(); string date = dtpPaymentDate.Value.Date.ToString("yyyy-MM-dd"); string payAmount = txtAmount.Text.ToString(); string chequeNo = txtChequeNo.Text.ToString(); string bank = cmbBank.Text.ToString(); string note = txtNote.Text.ToString(); string q1 = "INSERT INTO payments(paymentno, customer, amount,paymentdate,invoiceno) VALUES('" + paymentNo + "','" + cusNo + "', '" + payAmount + "','" + date + "','" + cmb_InvoiceNo.Text + "')"; bool status1 = middle_access.db_access.InsertData(q1); //check dates what are isuue date etc... string q2 = "INSERT INTO cheque (payments,chequeno, note, givendate, bank, status, duedate,isCashCheque) VALUES ('" + paymentNo + "', '" + chequeNo + "', '" + note + "','" + date + "' , '" + bank + "', 'P', '2012-03-04','" + isCashCheque + "')"; bool status2 = middle_access.db_access.InsertData(q2); if (status1 == true && status2 == true) // if data is insert { // if (GlobleAccess.openType == "M") // { insertAccountDetaila(); // } MessageBox.Show("Check Payment successfully added!"); Clear(); autoIncrement(); if (GlobleAccess.openType != "I") { Insert_Data_To_temp_invoice_print(); } // CurrentInvoicePrint.paymenCount = GlobleAccess.Get_Payments_Sum(); CurrentInvoicePrint ci = new CurrentInvoicePrint(); ci.Show(); } else { MessageBox.Show("Error : Payment not added !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } ///////////////////////////// } } setAmount(); }
private void radButton1_Click_1(object sender, EventArgs e) { if (cmb_InvoiceNo.Text == "") { MessageBox.Show("Please select an invoice number!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { /*Payments_Full_Report pr = new Payments_Full_Report(); pr.MdiParent = DHNAULA.ActiveForm; pr.Show();*/ bool status = false; string invoice_no = cmb_InvoiceNo.Text; GlobleAccess.invoiceNo = invoice_no; string q = "SELECT I.invoiceno,I.invoicedate,C.customername,IL.itemno,IL.itemname,IL.soldqty,IL.retailprice,IL.soldqty*IL.retailprice,I.invoicetotal,IL.discount,I.invoicenote,I.vehicleno FROM invoice I,invoicelines IL, customer C WHERE C.customerno = I.customer AND I.invoiceno = IL.invoiceno AND I.invoiceno = '" + invoice_no + "'"; DataSet ds_invoice = middle_access.db_access.SelectData(q); if (ds_invoice != null) { // int i = 0; for (int i = 0; i < ds_invoice.Tables[0].Rows.Count; i++) { DataRow dr_invoice = ds_invoice.Tables[0].Rows[i]; string invoice_date = dr_invoice.ItemArray.GetValue(1).ToString(); string customer_name = dr_invoice.ItemArray.GetValue(2).ToString(); string item_no = dr_invoice.ItemArray.GetValue(3).ToString(); string item_name = dr_invoice.ItemArray.GetValue(4).ToString(); string qty = dr_invoice.ItemArray.GetValue(5).ToString(); string unit_price = dr_invoice.ItemArray.GetValue(6).ToString(); string price = dr_invoice.ItemArray.GetValue(7).ToString(); string total_price = dr_invoice.ItemArray.GetValue(8).ToString(); string discount = dr_invoice.ItemArray.GetValue(9).ToString(); string refNo = dr_invoice.ItemArray.GetValue(10).ToString(); string vehicleNo = dr_invoice.ItemArray.GetValue(11).ToString(); if (discount == "") { discount = " "; price = ((Convert.ToDouble(qty) * Convert.ToDouble(unit_price)) / 100 * (100 - 0)).ToString(); } else if (discount != " ") { price = ((Convert.ToDouble(qty) * Convert.ToDouble(unit_price)) / 100 * (100 - Convert.ToDouble(discount))).ToString(); discount = discount + " %"; } string q3 = "INSERT INTO temp_invoice_print(invoice_no,invoice_date,customer_name,item_no,item_name,qty,unit_price,price,total_price,discount,refNo,vehicleNo)VALUES('" + invoice_no + "','" + invoice_date + "','" + customer_name + "','" + item_no + "','" + item_name + "','" + qty + "','" + unit_price + ".00','" + price + ".00','" + total_price + ".00','" + discount + "','" + refNo + "','" + vehicleNo + "')"; status = middle_access.db_access.InsertData(q3); } if (status) { this.Enabled = false; CurrentInvoicePrint ci = new CurrentInvoicePrint(); ci.MdiParent = DHNAULA.ActiveForm; ci.Show(); } else { MessageBox.Show("Invoice number error!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void btnPrintInvoice_Click(object sender, EventArgs e) { if (grdInvoice.RowCount < 1) { MessageBox.Show("Empty invoice!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (txtInvoiceNo.Text != "" && txtCustomerName.Text != "" && grdInvoice.RowCount != 0)//if customerNo is not null { for (int i = 0; i < grdInvoice.Rows.Count; i++) { double discount = Convert.ToDouble(grdInvoice.Rows[i].Cells[5].Value); double discountedPrice = ((Convert.ToDouble(grdInvoice.Rows[i].Cells[2].Value) * Convert.ToDouble(grdInvoice.Rows[i].Cells[3].Value)) / 100) * (100 - discount); string vehicleNo = txtVehicleNo.Text; string q3 = ""; if (discount == 0.00) { q3 = "INSERT INTO temp_invoice_print(invoice_no,invoice_date,customer_name,item_no,item_name,qty,unit_price,price,total_price,discount,refNo,vehicleno)VALUES('" + txtInvoiceNo.Text + "','" + dtpInvoiceDate.Value.Date.ToString("yyyy-MM-dd") + "','" + txtCustomerName.Text + "','" + grdInvoice.Rows[i].Cells[0].Value.ToString() + "','" + grdInvoice.Rows[i].Cells[1].Value.ToString() + "'," + grdInvoice.Rows[i].Cells[2].Value.ToString() + ",'" + grdInvoice.Rows[i].Cells[3].Value.ToString() + "','" + discountedPrice.ToString("0.00") + "','" + txtTotal.Text + "',' ','" + txtInvoiceNote.Text + "','" + vehicleNo + "')"; } else { q3 = "INSERT INTO temp_invoice_print(invoice_no,invoice_date,customer_name,item_no,item_name,qty,unit_price,price,total_price,discount,refNo,vehicleno)VALUES('" + txtInvoiceNo.Text + "','" + dtpInvoiceDate.Value.Date.ToString("yyyy-MM-dd") + "','" + txtCustomerName.Text + "','" + grdInvoice.Rows[i].Cells[0].Value.ToString() + "','" + grdInvoice.Rows[i].Cells[1].Value.ToString() + "'," + grdInvoice.Rows[i].Cells[2].Value.ToString() + ",'" + grdInvoice.Rows[i].Cells[3].Value.ToString() + "','" + discountedPrice.ToString("0.00") + "','" + txtTotal.Text + "','" + discount.ToString() + " %" + "','" + txtInvoiceNote.Text + "','" + vehicleNo + "')"; } bool status3 = middle_access.db_access.InsertData(q3); if (status3 != true) { MessageBox.Show("Error!"); string q4 = "DELETE FROM temp_invoice_print"; middle_access.db_access.DeleteData(q4); break; } } this.Enabled = false; CurrentInvoicePrint ci = new CurrentInvoicePrint(); ci.Show(); print(); } else { MessageBox.Show("Invalid operation!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }