0172fc4e01
Added Nc Option in settlement Merged Vouchers and SaleVoucher table. Need to update the Sql Schema
160 lines
5.4 KiB
C#
160 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using Tanshu.Accounts.Helpers;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Accounts.BI;
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
{
|
|
public partial class ProductsForm : Form
|
|
{
|
|
bool createOnly = false;
|
|
List<ProductDisplayBO> productList = new List<ProductDisplayBO>();
|
|
Guid? _productID;
|
|
ProductBO product;
|
|
#region Form Load
|
|
public ProductsForm(Guid? productID)
|
|
{
|
|
_productID = productID;
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Products_Load(object sender, EventArgs e)
|
|
{
|
|
FillCombos();
|
|
if (_productID.HasValue)
|
|
{
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
|
{
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
{
|
|
product = dao.GetProduct(_productID.Value);
|
|
}
|
|
}
|
|
|
|
txtUniqueID.Text = product.Code.ToString();
|
|
txtName.Text = product.Name;
|
|
cmbUnits.SelectedItem = product.Units;
|
|
cmbProductGroups.SelectedValue = product.ProductGroupID;
|
|
txtSalePrice.Text = product.SalePrice.ToString();
|
|
cmbVat.SelectedValue = product.VatID;
|
|
cmbServiceTax.SelectedValue = product.ServiceTaxID;
|
|
chkDiscontinued.Checked = product.Discontinued;
|
|
btnSave.Text = "&Update";
|
|
btnDelete.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
btnSave.Text = "&Save";
|
|
btnDelete.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void FillCombos()
|
|
{
|
|
string[] units = { "Can", "Gms", "Rs.", "Piece", "Liter", "Plate", "Kg.", "Bottle", "Pack" };
|
|
bsUnits.DataSource = units;
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
|
{
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
{
|
|
bsProductGroups.DataSource = dao.GetProductGroups();
|
|
bsVat.DataSource = dao.GetTaxes();
|
|
bsServiceTax.DataSource = dao.GetTaxes();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Buttons
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
|
|
return;
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
|
{
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
{
|
|
if (dao.Delete(product.ProductID))
|
|
{
|
|
btnCancel_Click(sender, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnUpdate_Click(object sender, EventArgs e)
|
|
{
|
|
if (!ValidateValues())
|
|
{
|
|
MessageBox.Show("Missing Information: Please check the form.");
|
|
txtName.Focus();
|
|
}
|
|
else if (MessageBox.Show("Are you sure?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
|
|
{
|
|
Save();
|
|
btnCancel_Click(sender, e);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Add / Edit / Delete
|
|
private bool ValidateValues()
|
|
{
|
|
bool returnType;
|
|
returnType = (bool)(txtName.Text.Trim().Length > 0 ? true : false);
|
|
returnType = (cmbVat.SelectedValue == null ? false : true);
|
|
returnType = (cmbServiceTax.SelectedValue == null ? false : true);
|
|
return returnType;
|
|
}
|
|
|
|
private void Save()
|
|
{
|
|
if (product == null)
|
|
product = new ProductBO();
|
|
product.Name = txtName.Text;
|
|
product.Units = cmbUnits.Text;
|
|
product.ProductGroupID = new Guid(cmbProductGroups.SelectedValue.ToString());
|
|
product.SalePrice = Convert.ToDecimal(txtSalePrice.Text);
|
|
if (cmbServiceTax.SelectedValue != null)
|
|
product.ServiceTaxID = new Guid(cmbServiceTax.SelectedValue.ToString());
|
|
product.Discontinued = chkDiscontinued.Checked;
|
|
product.VatID = new Guid(cmbVat.SelectedValue.ToString());
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
|
{
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
{
|
|
if (product.ProductID == new Guid())
|
|
dao.Insert(product);
|
|
else
|
|
dao.Update(product);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnAddCategory_Click(object sender, EventArgs e)
|
|
{
|
|
using (var frm = new ProductGroups())
|
|
{
|
|
frm.ShowDialog();
|
|
}
|
|
FillCombos();
|
|
cmbProductGroups.SelectedIndex = 0;
|
|
}
|
|
public ProductBO Product
|
|
{
|
|
get { return null; }
|
|
}
|
|
}
|
|
} |