public void btn_Click(Object sender, EventArgs e) { switch (((LinkButton)sender).ID) { case "Purchase_Submit": rvBillNumber.Validate(); cvBillingDate.Validate(); rvBillingDate.Validate(); rvExpirationDate.Validate(); if (rvBillNumber.IsValid && cvBillingDate.IsValid && rvBillingDate.IsValid && rvExpirationDate.IsValid) { InsertNewPurchase(PurchaseID.ToString()); CardPurchase.Visible = false; RepeaterPurchase.Visible = true; } break; case "Purchase_Exit": CardPurchase.Visible = false; RepeaterPurchase.Visible = true; break; case "NewPurchase": ClearTextBoxPurchase(CardPurchase.Controls.GetEnumerator()); Session.Remove("newBillProd"); RepeaterPurchaseProduct.Visible = false; CardPurchase.Visible = true; RepeaterPurchase.Visible = false; NewPurchase.Visible = false; GoBackPurc.Visible = true; break; } }
public void FillProduct() { ArrayList pp = new ArrayList(); if (!FromQuote) { DataSet ds = DatabaseConnection.CreateDataset("SELECT * FROM CRM_BILL WHERE ID=" + PurchaseID); Purchase_ID.Text = PurchaseID.ToString(); Purchase_BillingDate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["BillingDate"]).ToShortDateString(); Purchase_PaymentDate.Text = (ds.Tables[0].Rows[0]["PaymentDate"] != DBNull.Value) ? Convert.ToDateTime(ds.Tables[0].Rows[0]["PaymentDate"]).ToShortDateString() : ""; Purchase_ExpirationDate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["ExpirationDate"]).ToShortDateString(); Purchase_BillNumber.Text = ds.Tables[0].Rows[0]["BillNumber"].ToString(); Purchase_Note.Text = ds.Tables[0].Rows[0]["Note"].ToString(); Purchase_Payment.Checked = (bool)ds.Tables[0].Rows[0]["Payment"]; if ((long)ds.Tables[0].Rows[0]["OwnerID"] > 0) { this.Purchase_TextboxOwnerID.Text = ds.Tables[0].Rows[0]["OwnerID"].ToString(); this.Purchase_TextboxOwner.Text = DatabaseConnection.SqlScalar("SELECT ISNULL(NAME,'')+' '+ISNULL(SURNAME,'') AS OWNER FROM ACCOUNT WHERE UID=" + ds.Tables[0].Rows[0]["OwnerID"].ToString()); } else { this.Purchase_TextboxOwnerID.Text = string.Empty; this.Purchase_TextboxOwner.Text = string.Empty; } ds.Clear(); ds = DatabaseConnection.CreateDataset("SELECT * FROM CRM_BILLROWS WHERE BILLID=" + PurchaseID); foreach (DataRow d in ds.Tables[0].Rows) { PurchaseProduct Pprod = new PurchaseProduct(); Pprod.id = Convert.ToInt64(d["ProductID"]); Pprod.ShortDescription = DatabaseConnection.SqlScalar("SELECT SHORTDESCRIPTION FROM CATALOGPRODUCTS WHERE ID=" + d["ProductID"].ToString()); Pprod.LongDescription = d["Description"].ToString(); Pprod.UM = (string)d["UM"]; Pprod.Qta = (int)d["Qta"]; Pprod.UnitPrice = (decimal)d["UnitPrice"]; Pprod.Vat = Convert.ToInt32(d["Tax"]); Pprod.ListPrice = (decimal)d["ListPrice"]; Pprod.FinalPrice = (decimal)d["FinalPrice"]; Pprod.ObId = pp.Count; pp.Add(Pprod); } } else { DataSet ds = DatabaseConnection.CreateDataset("SELECT * FROM QUOTE_VIEW WHERE QUOTEID=" + this.QuoteID); Purchase_ID.Text = QuoteID.ToString(); Purchase_BillingDate.Text = DateTime.Now.ToShortDateString(); Purchase_PaymentDate.Text = String.Empty; Purchase_ExpirationDate.Text = String.Empty; Purchase_BillNumber.Text = String.Empty; Purchase_Note.Text = ds.Tables[0].Rows[0]["Description"].ToString(); Purchase_Payment.Checked = false; if ((int)ds.Tables[0].Rows[0]["OwnerID"] > 0) { this.Purchase_TextboxOwnerID.Text = ds.Tables[0].Rows[0]["OwnerID"].ToString(); this.Purchase_TextboxOwner.Text = DatabaseConnection.SqlScalar("SELECT ISNULL(NAME,'')+' '+ISNULL(SURNAME,'') AS OWNER FROM ACCOUNT WHERE UID=" + ds.Tables[0].Rows[0]["OwnerID"].ToString()); } else { this.Purchase_TextboxOwnerID.Text = string.Empty; this.Purchase_TextboxOwner.Text = string.Empty; } ds.Clear(); DataTable dt = DatabaseConnection.CreateDataset("SELECT * FROM ESTIMATEDROWS WHERE ESTIMATEID=" + QuoteID).Tables[0]; foreach (DataRow ddr in dt.Rows) { if (ddr["CatalogID"].ToString() != "0") { DataSet tempNP = DatabaseConnection.CreateDataset("SELECT * FROM CATALOGPRODUCTS WHERE ID=" + ddr["CatalogID"].ToString()); if (tempNP.Tables[0].Rows.Count > 0) { DataRow pInfo = tempNP.Tables[0].Rows[0]; PurchaseProduct newprod = new PurchaseProduct(); newprod.id = Convert.ToInt64(ddr["CatalogID"]); newprod.ShortDescription = pInfo["ShortDescription"].ToString(); newprod.LongDescription = pInfo["LongDescription"].ToString(); newprod.UM = pInfo["Unit"].ToString(); newprod.Qta = (double)ddr["Qta"]; newprod.UnitPrice = (decimal)ddr["Uprice"]; newprod.Vat = (pInfo["Vat"] != DBNull.Value) ? (decimal)pInfo["Vat"] : 0; newprod.ListPrice = Math.Round(Convert.ToDecimal(newprod.Qta) * newprod.UnitPrice, 2); newprod.FinalPrice = (decimal)ddr["NewUPrice"]; try { newprod.Reduction = (int)ddr["reduction"]; } catch { newprod.Reduction = 0; } pp.Add(newprod); } } else { PurchaseProduct newprod = new PurchaseProduct(); newprod.id = 0; newprod.ShortDescription = ddr["Description"].ToString(); newprod.LongDescription = ddr["Description"].ToString(); newprod.UM = ""; newprod.Qta = (double)ddr["qta"]; newprod.UnitPrice = (decimal)ddr["Uprice"]; newprod.Vat = 0; newprod.ListPrice = Math.Round(Convert.ToDecimal(newprod.Qta) * newprod.UnitPrice, 2); newprod.FinalPrice = (decimal)ddr["NewUPrice"]; try { newprod.Reduction = (int)ddr["reduction"]; } catch { newprod.Reduction = 0; } pp.Add(newprod); } } } Session["newBillProd"] = pp; RepeaterPurchaseProduct.DataSource = pp; RepeaterPurchaseProduct.DataBind(); RepeaterPurchaseProduct.Visible = true; }