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.

147 lines
6.0 KiB

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;
using BiskLog_Point_Of_Sale.Multiple_Login;
using BiskLog_Point_Of_Sale.Properties;
namespace Point_Of_Sale_Managment
{
public partial class AddProducttoCart : Form
{
SqlConnection cn;
SqlCommand command;
DatabaseConn conn = new DatabaseConn();
SqlDataReader dr;
string currency;
public static string id, product_name, price, quantity,unitname,unitcode,distinctive;
SalesPOS formSale;
public AddProducttoCart(SalesPOS formsales = null)
{
InitializeComponent();
cn = new SqlConnection(conn.MyConnection());
formSale = formsales;
currency = Settings.Default.currrencyCode + " ";
}
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1)
{
string colName = dataGridView1.Columns[e.ColumnIndex].Name;
id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
product_name = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
price = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
quantity = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
unitname = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
unitcode= dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
distinctive = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
if (int.Parse(quantity) <= 0)
{
string title = "Out of stock";
string message = "Sorry, " + product_name + " is out of stock!!";
NoAction noAction = new NoAction(title, message);
noAction.BringToFront();
noAction.ShowDialog();
}
else
{
quantityManual quant = new quantityManual(this);
quant.BringToFront();
quant.ShowDialog();
}
}
}
public void AddtoCart(string pid, string productName, string pPrice, int quantity,string unitname,string unitCode,string distinctive)
{
formSale.loadProductManual(pid, productName, pPrice, quantity,unitname,unitCode,distinctive);
dataGridView1.Rows.Clear();
proID.Text = "";
proNAME.Text = "";
}
public void products(string key)
{
dataGridView1.Rows.Clear();
cn.Open();
command = new SqlCommand("Select tblProduct.pcode,tblProduct.product_name,tblProduct.pdesc,tblInventory.quantity,tblProduct.price,uni.unitname as unit,tblProduct.baseUnit from tblProduct Inner Join tblInventory On tblInventory.pcode =" +
"tblProduct.pcode Inner Join UnitOfMeasure uni On uni.unitCode = tblProduct.baseUnit where tblProduct.branchID = @branch and tblProduct.status = 'ACTIVE' and tblProduct.pcode like '%" + key + "%' or " +
"tblProduct.branchID = @branch and tblProduct.status = 'ACTIVE' and tblProduct.product_name like '%" + key + "%' " +
"SELECT PAU.pcode,tp.product_name,tp.pdesc ,uni.unitname,[price/unit] as price,(ti.quantity / [quantity/unit]) as quantity,PAU.unitCode ,distinctiveCode " +
"FROM ProductAltUnit PAU Inner Join UnitOfMeasure uni On uni.unitCode = PAU.unitCode Inner Join tblProduct tp On tp.pcode = PAU.pcode " +
"Inner Join tblInventory ti On ti.pcode = PAU.pcode where tp.branchID = @branch and tp.status = 'ACTIVE' and PAU.pcode like '%" + key + "%' or " +
"tp.branchID = @branch and tp.status = 'ACTIVE' and tp.product_name like '%" + key + "%'", cn);
command.Parameters.AddWithValue("@branch", Form1.branch);
command.ExecuteNonQuery();
dr = command.ExecuteReader();
while (dr.Read())
{
dataGridView1.Rows.Add(dr[0].ToString(), dr["product_name"].ToString(), dr["pdesc"].ToString(), currency + dr["price"].ToString(), dr["quantity"].ToString(),dr["unit"].ToString(),dr["baseUnit"].ToString(),dr[0].ToString());
}
dr.NextResult();
while (dr.Read())
{
dataGridView1.Rows.Add(dr[0].ToString(), dr["product_name"].ToString(), dr["pdesc"].ToString(), currency + dr["price"].ToString(), dr["quantity"].ToString(), dr["unitname"].ToString(), dr["unitCode"].ToString(), dr["distinctiveCode"].ToString());
}
dr.Close();
cn.Close();
}
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;
}
private void AddProducttoCart_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}
private void ProID_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(proID.Text))
{
dataGridView1.Rows.Clear();
}
else
{
products(proID.Text);
}
}
private void ProNAME_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(proNAME.Text))
{
dataGridView1.Rows.Clear();
}
else
{
products(proNAME.Text);
}
}
}
}