You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
5.5 KiB
141 lines
5.5 KiB
3 months ago
|
using BiskLog_Point_Of_Sale.Classes;
|
||
|
using BiskLog_Point_Of_Sale.Properties;
|
||
|
using Point_Of_Sale_Managment;
|
||
|
using Point_Of_Sale_Managment.Cashier_Module.Invoice;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel;
|
||
|
using System.Data;
|
||
|
using System.Data.SqlClient;
|
||
|
using System.Drawing;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows.Forms;
|
||
|
|
||
|
namespace BiskLog_Point_Of_Sale.Invoice
|
||
|
{
|
||
|
public partial class CashierInvoiceDialog : Form
|
||
|
{
|
||
|
CashierInvoiceMain invoiceMain;
|
||
|
SqlConnection cn;
|
||
|
SqlCommand cm;
|
||
|
SqlDataReader dr;
|
||
|
DatabaseConn conn = new DatabaseConn();
|
||
|
public CashierInvoiceDialog(CashierInvoiceMain main, string id, string totalCost, string status)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
cn = new SqlConnection(conn.MyConnection());
|
||
|
invoiceMain = main;
|
||
|
lblInvoice.Text = id;
|
||
|
lblTotalCost.Text = totalCost;
|
||
|
if (status == "SOLD")
|
||
|
{
|
||
|
button1.Enabled = false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
button1.Enabled = true;
|
||
|
}
|
||
|
holding.Left = (ClientSize.Width - holding.Width) / 2;
|
||
|
}
|
||
|
|
||
|
private void CloseBTN_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
this.Close();
|
||
|
}
|
||
|
|
||
|
private void CloseBTN_MouseEnter(object sender, EventArgs e)
|
||
|
{
|
||
|
closeBTN.BackColor = Color.Crimson;
|
||
|
}
|
||
|
|
||
|
private void CloseBTN_MouseLeave(object sender, EventArgs e)
|
||
|
{
|
||
|
closeBTN.BackColor = Color.Transparent;
|
||
|
}
|
||
|
public int LoadInvoice()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
int i = 1;
|
||
|
invoiceDetails.Invoke(new Action(() =>
|
||
|
{
|
||
|
invoiceDetails.Rows.Clear();
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Select I.pcode,P.product_name,I.quantity,I.totalprice,uni.unitname,I.unit,P.baseUnit from tblInvoice I Inner Join tblProduct P On " +
|
||
|
"P.pcode = I.pcode Inner Join UnitOfMeasure uni On uni.unitCode = I.unit where I.invoiceID = @invoiceID and I.branchID = @branchID " +
|
||
|
"Select I.pcode,P.product_name,I.quantity,I.totalprice,uni.unitname,I.unit,PAU.distinctiveCode from tblInvoice I Inner Join tblProduct P On " +
|
||
|
"P.pcode = I.pcode Inner Join UnitOfMeasure uni On uni.unitCode = I.unit Inner Join ProductAltUnit PAU On PAU.unitCode = I.unit and PAU.pcode = I.pcode " +
|
||
|
"where I.invoiceID = @invoiceID and I.branchID = @branchID", cn);
|
||
|
cm.Parameters.AddWithValue("@invoiceID", lblInvoice.Text);
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
if (dr[5].ToString().Equals(dr[6].ToString()))
|
||
|
{
|
||
|
invoiceDetails.Rows.Add(i, dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[4].ToString()
|
||
|
, Settings.Default.currrencyCode + " " + dr[3].ToString(), dr[5].ToString(), dr[0].ToString());
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
dr.NextResult();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
invoiceDetails.Rows.Add(i, dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[4].ToString()
|
||
|
, Settings.Default.currrencyCode + " " + dr[3].ToString(), dr[5].ToString(), dr[6].ToString());
|
||
|
i++;
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
cn.Close();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private async void InvoiceDialog_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
Task<int> task = new Task<int>(LoadInvoice);
|
||
|
holding.Visible = true;
|
||
|
task.Start();
|
||
|
await task;
|
||
|
holding.Visible = false;
|
||
|
}
|
||
|
private List<InvoicePOS> getList()
|
||
|
{
|
||
|
List<InvoicePOS> invoices = new List<InvoicePOS>();
|
||
|
foreach (DataGridViewRow row in invoiceDetails.Rows)
|
||
|
{
|
||
|
decimal total = decimal.Parse(row.Cells[5].Value.ToString().Substring(Settings.Default.currrencyCode.Length));
|
||
|
int quantity = int.Parse(row.Cells[3].Value.ToString());
|
||
|
decimal unit = total / quantity;
|
||
|
InvoicePOS invoice = new InvoicePOS(
|
||
|
productCode: row.Cells[1].Value.ToString(), quantity: quantity,
|
||
|
totalprice: total, unitprice: unit,
|
||
|
productname: row.Cells[2].Value.ToString(),
|
||
|
unitCode: row.Cells[6].Value.ToString(),
|
||
|
unitName: row.Cells[4].Value.ToString(),
|
||
|
distinctiveCode: row.Cells[7].Value.ToString()
|
||
|
);
|
||
|
invoices.Add(invoice);
|
||
|
|
||
|
|
||
|
}
|
||
|
return invoices;
|
||
|
}
|
||
|
private void Button1_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
string id = "";
|
||
|
lblInvoice.Invoke(new Action(() => id = lblInvoice.Text));
|
||
|
invoiceMain.ShowSalesPOS(this, getList(), lblInvoice.Text);
|
||
|
}
|
||
|
}
|
||
|
}
|