public int add_product(cls_product prod) { //prod.reset_data_by_mode(this.isnonvat, this.issenior, this.iswholesale, this.pricingtype); if (prod.getQty() == 0) { return(-1); } for (int i = 0; i < list_product.Count; i++) { if (list_product[i].getSyncId() == prod.getSyncId() && prod.getSyncId() != 0 && prod.getBarcode() != "-") { decimal qty = list_product[i].getQty() + prod.getQty(); if (qty == 0) { this.remove_product(i); return(i); } list_product[i].setQty(qty); list_product[i].reset_data_by_mode(this.isnonvat, this.issenior, this.iswholesale, this.pricingtype, this.pricingrate, this.customer); this.sync_product_row(i); return(i); } } int row_index = this.list_product.Count; this.list_product.Add(prod); this.dtproducts.Rows.Add(dtproducts.NewRow()); this.sync_product_row(row_index); return(row_index); }
public int add_offline_product(cls_product prod) { for (int i = 0; i < list_product.Count; i++) { Console.WriteLine(prod.getBarcode() + " == " + prod.getBarcode()); if (list_product[i].getBarcode() == prod.getBarcode()) { decimal qty = list_product[i].getQty() + prod.getQty(); if (qty == 0) { this.remove_product(i); return(i); } list_product[i].setQty(qty); list_product[i].setPrice(prod.getPrice()); return(i); } } int row_index = this.list_product.Count; this.list_product.Add(prod); this.dtproducts.Rows.Add(dtproducts.NewRow()); this.sync_product_row(row_index); return(row_index); }
public int add_product_by_barcode(string barcode_d) { cls_product prod = new cls_product(barcode_d); if (prod.getSyncId() == 0) { return(-1); } return(this.add_product(prod)); }
public void reset_product_data(int row_index) { cls_product prod = this.list_product[row_index]; prod.reset_data_by_mode(this.isnonvat, this.issenior, this.iswholesale, this.pricingtype, this.pricingrate, this.customer); }
public void set_productlist_by_wid(long syncid_d, bool is_history) { string sSQL = "SELECT * FROM `saleshead` WHERE `SyncId` = " + syncid_d; DataTable dt = mySQLFunc.getdb(sSQL); if (dt.Rows.Count <= 0) { return; } DataRow dr = dt.Rows[0]; this.isnonvat = (Convert.ToInt32(dr["isnonvat"]) == 1); this.iswholesale = (Convert.ToInt32(dr["iswholesale"]) == 1); this.issenior = (dr["seniorno"].ToString() != ""); sSQL = @"SELECT P.`product`, SD.`SyncId`,SD.`productid`, SD.`quantity`, SD.`oprice`, SD.`price` AS 'aprice', SD.`discount1`, SD.`vat`, SD.`soldby` FROM `salesdetail` AS SD LEFT JOIN `product` AS P ON P.`SyncId` = SD.`productid` WHERE SD.`headid` = " + syncid_d + " ORDER BY SD.`id` "; dt = mySQLFunc.getdb(sSQL); if (dt.Rows.Count <= 0) { return; } foreach (DataRow dr_d in dt.Rows) { int pwid = Convert.ToInt32(dr_d["productid"]); Console.WriteLine("1: " + pwid + ": " + dr_d["aprice"]); cls_product prod; if (pwid == 0) { prod = new cls_product(0, false, false); prod.setProductName(dr_d["product"].ToString()); } else if (pwid == 1) { prod = new cls_product(1, false, true); prod.setProductName("Service Charge: " + cls_globalvariables.ServiceCharge_v + "%"); } else if (pwid == 2) { prod = new cls_product(2, false, true); prod.setProductName("Local Tax: " + cls_globalvariables.LocalTax_v + "%"); prod.setRetailPrice(Convert.ToDecimal(dr_d["oprice"])); } else if (pwid != 0) { prod = new cls_product(pwid, true, true); } else { prod = new cls_product(pwid, false, true); } int tempWid = int.TryParse(dr_d["SyncId"].ToString(), out tempWid) ? tempWid : 0; prod.setRetailPrice(Convert.ToDecimal(dr_d["oprice"])); prod.setOrigPrice(Convert.ToDecimal(dr_d["oprice"])); prod.setQty(Convert.ToDecimal(dr_d["quantity"])); prod.setSoldBy(new cls_user(Convert.ToInt32(dr_d["soldby"]))); prod.setPrice(Convert.ToDecimal(dr_d["aprice"])); if (prod.getOrigPrice() != 0) { decimal dc = decimal.Divide(prod.getPrice(), prod.getOrigPrice()); prod.setDiscount(1M - dc); prod.setAdjust(0); } decimal oprice = Convert.ToDecimal(dr_d["oprice"]); decimal oprice_temp = Convert.ToDecimal(dr_d["oprice"]); decimal temp_price = Convert.ToDecimal(dr_d["aprice"]); decimal temp_discount = Convert.ToDecimal(dr_d["discount1"]); decimal temp_adjust = Convert.ToDecimal(dr_d["aprice"]) - (Convert.ToDecimal(dr_d["oprice"]) * (1 - Convert.ToDecimal(dr_d["discount1"]))); if (this.issenior && (prod.getIsSenior() == 1)) { oprice_temp = (oprice / (1 + cls_globalvariables.vat)) * (1 - cls_globalvariables.senior); } if (this.issenior && (prod.getIsSenior() == 2)) { oprice_temp = (oprice * (1 - cls_globalvariables.senior5)); } else if (this.isnonvat && prod.getIsVat()) { oprice_temp = oprice / (1 + cls_globalvariables.vat); } else { } if (Math.Round(oprice_temp, 3, MidpointRounding.AwayFromZero) != Math.Round(temp_price, 3, MidpointRounding.AwayFromZero) && temp_discount > 0) { prod.setDiscount(temp_discount); } else if (Math.Round(oprice_temp, 3, MidpointRounding.AwayFromZero) != Math.Round(temp_price, 3, MidpointRounding.AwayFromZero) && temp_discount == 0) { prod.setAdjust(temp_adjust); } else { } prod.reprint_reset_data_by_mode(this.isnonvat, this.issenior, this.iswholesale, this.pricingtype); this.list_product.Add(prod); this.dtproducts.Rows.Add(dtproducts.NewRow()); Console.WriteLine(prod.getProductName() + ": " + prod.getPrice()); } this.sync_product_all(); }