Biskilog POS desktop appilcation
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.

156 lines
6.2 KiB

using BiskLog_Point_Of_Sale.Cashier_Module;
using BiskLog_Point_Of_Sale.Classes;
using BiskLog_Point_Of_Sale.Company_Setup;
using BiskLog_Point_Of_Sale.Dialogs;
using BiskLog_Point_Of_Sale.Multiple_Login;
using BiskLog_Point_Of_Sale.Properties;
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 Point_Of_Sale_Managment.CashierModule
{
public partial class SaleCancellation : Form
{
SqlConnection cn;
SqlCommand cm;
SqlDataReader dr;
DatabaseConn conn = new DatabaseConn();
public SaleCancellation()
{
InitializeComponent();
cn = new SqlConnection(conn.MyConnection());
}
private void SaleCancellation_Load(object sender, EventArgs e)
{
}
private void SaleCancellation_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}
private void TextBox1_TextChanged(object sender, EventArgs e)
{
getReceipt(textBox1.Text);
}
public void cancelSales(string transactionKey)
{
SqlTransaction transaction;
cn.Open();
transaction = cn.BeginTransaction();
try
{
cm = new SqlCommand("Update tblCart set status = @status where branchID = @branch and transno = @transno", cn);
cm.Parameters.AddWithValue("@status", "CANCELLED");
cm.Parameters.AddWithValue("@transno", transactionKey);
cm.Parameters.AddWithValue("@branch", CashierMain.branch);
cm.Transaction = transaction;
cm.ExecuteNonQuery();
cm = new SqlCommand("Insert into tblCancelledTransactions (transno,dateCancelled,cancelledBy,branchID,countID) " +
"values (@transno,@dateCancelled,@cancelledBy,@branchID,@countID)", cn);
cm.Parameters.AddWithValue("@dateCancelled", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
cm.Parameters.AddWithValue("@transno", transactionKey);
cm.Parameters.AddWithValue("@branchID", CashierMain.branch);
cm.Parameters.AddWithValue("@cancelledBy", MainLogin.login_user);
cm.Parameters.AddWithValue("@countID", transactionKey + CashierMain.branch + DateTime.Now.ToString("yyyyMMddHHmmssfff"));
cm.Transaction = transaction;
cm.ExecuteNonQuery();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
cm = new SqlCommand("Declare @newQuantity int = (Select MAX(quantity) + MIN(@quantity) from tblInventory where pcode = @pcode and branchID = @branchID) " +
"Update tblInventory set quantity = @newQuantity where branchID = @branchID and pcode = @pcode " +
"Insert into tblInventoryEntries(pcode, quantity, date, countID, branchID) values (@pcode,@newQuantity,@date,@countID,@branchID)", cn);
cm.Parameters.AddWithValue("@quantity", row.Cells[3].Value.ToString());
cm.Parameters.AddWithValue("@pcode", row.Cells[5].Value.ToString());
cm.Parameters.AddWithValue("@date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
cm.Parameters.AddWithValue("@branchID", CashierMain.branch);
cm.Parameters.AddWithValue("@countID", transactionKey + CashierMain.branch + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
cm.Transaction = transaction;
cm.ExecuteNonQuery();
}
transaction.Commit();
cn.Close();
string title = "Cancelled";
string message = "Receipt with transaction number " + transactionKey + " has been cancelled successfully";
NoAction noAction = new NoAction(title, message);
noAction.BringToFront();
noAction.ShowDialog();
}
catch (Exception ex)
{
transaction.Rollback();
cn.Close();
ErrorLogging.WriteToFile(ex.ToString());
}
}
public void getReceipt(string key)
{
int i = 1;
try
{
cn.Open();
cm = new SqlCommand("Select tblProduct.product_name, tblCart.price,tblCart.quantity,tblCart.total,date,tblCart.id " +
"from tblCart Inner Join tblProduct On tblProduct.pcode = tblCart.id where tblCart.branchID = @branch " +
"and transno = @transaction and tblCart.status = 'SOLD'", cn);
cm.Parameters.AddWithValue("@transaction", key);
cm.Parameters.AddWithValue("@branch", CashierMain.branch);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
dateP.Value = Convert.ToDateTime(dr[4].ToString());
dataGridView1.Rows.Add(i, dr[0].ToString().ToUpper(), dr[1].ToString().ToUpper(), dr[2].ToString(), dr[3].ToString(), dr[5].ToString());
i++;
}
dr.Close();
cn.Close();
}
catch
{
cn.Close();
}
}
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 8)
{
//accepts backspace
}
else if ((e.KeyChar < 48) || (e.KeyChar > 57)) //ascii code 48-57 between 0-9
{
e.Handled = true;
}
}
private void Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Exit_MouseEnter(object sender, EventArgs e)
{
exit.BackColor = Color.Crimson;
}
private void Exit_MouseLeave(object sender, EventArgs e)
{
exit.BackColor = Color.Transparent;
}
}
}