示例#1
0
        private void InsertNewPurchase(string id)
        {
            decimal   subTotal = 0;
            string    BillID;
            ArrayList pp = new ArrayList();

            using (DigiDapter dg = new DigiDapter())
            {
                if (Session["newBillProd"] != null)
                {
                    pp = (ArrayList)Session["newBillProd"];
                    foreach (PurchaseProduct Pprod in pp)
                    {
                        subTotal += Pprod.FinalPrice;
                    }
                }

                dg.Add("BILLINGDATE", Convert.ToDateTime(((TextBox)CardPurchase.FindControl("Purchase_BillingDate")).Text, UC.myDTFI));
                dg.Add("EXPIRATIONDATE", Convert.ToDateTime(((TextBox)CardPurchase.FindControl("Purchase_ExpirationDate")).Text, UC.myDTFI));
                dg.Add("BILLNUMBER", ((TextBox)CardPurchase.FindControl("Purchase_BillNumber")).Text);
                if (((TextBox)CardPurchase.FindControl("Purchase_PaymentDate")).Text.Length > 0)
                {
                    dg.Add("PAYMENTDATE", Convert.ToDateTime(((TextBox)CardPurchase.FindControl("Purchase_PaymentDate")).Text, UC.myDTFI));
                }
                dg.Add("PAYMENT", (((CheckBox)CardPurchase.FindControl("Purchase_Payment")).Checked) ? 1 : 0);
                dg.Add("TOTALPRICE", subTotal);

                dg.Add("NOTE", ((TextBox)CardPurchase.FindControl("Purchase_Note")).Text);
                dg.Add("CREATEDDATE", DateTime.UtcNow);
                dg.Add("CREATEDBYID", UC.UserId);
                dg.Add("COMPANYID", RefID);
                dg.Add("LASTMODIFIEDDATE", DateTime.UtcNow);
                dg.Add("LASTMODIFIEDBYID", UC.UserId);

                if (Purchase_TextboxOwnerID.Text.Length > 0 && Convert.ToInt32(Purchase_TextboxOwnerID.Text) > 0)
                {
                    dg.Add("OWNERID", Convert.ToInt32(this.Purchase_TextboxOwnerID.Text));
                }
                else
                {
                    dg.Add("OWNERID", 0);
                }

                object newId = dg.Execute("CRM_BILL", "ID=" + id, DigiDapter.Identities.Identity);

                BillID = (id == "-1") ? newId.ToString() : id;
            }

            if (id != "-1")
            {
                DatabaseConnection.DoCommand("DELETE FROM CRM_BILLROWS WHERE BILLID=" + id);
            }

            if (pp.Count > 0)
            {
                foreach (PurchaseProduct Pprod in pp)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("CREATEDDATE", DateTime.UtcNow);
                        dg.Add("CREATEDBYID", UC.UserId);
                        dg.Add("LASTMODIFIEDDATE", DateTime.UtcNow);
                        dg.Add("LASTMODIFIEDBYID", UC.UserId);
                        dg.Add("BILLID", BillID);
                        dg.Add("DESCRIPTION", Pprod.LongDescription);
                        dg.Add("UNITPRICE", Pprod.UnitPrice);
                        dg.Add("LISTPRICE", Pprod.ListPrice);
                        dg.Add("FINALPRICE", Pprod.FinalPrice);
                        dg.Add("TAX", Pprod.Vat);
                        dg.Add("PRODUCTID", Pprod.id);
                        dg.Add("UM", Pprod.UM);
                        dg.Add("QTA", Pprod.Qta);
                        dg.Execute("CRM_BILLROWS");
                    }
                }
            }
            Session.Remove("newBillProd");

            if (this.FromQuote)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "registrato", "<script>alert('" + Root.rm.GetString("Esttxt45") + "');self.close();</script>");
            }
        }
示例#2
0
        public void RepeaterPurchaseCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "OpenPurchase":
                Literal PurchaseID = (Literal)e.Item.FindControl("PurchaseID");
                DataSet ds         = DatabaseConnection.CreateDataset("SELECT * FROM CRM_BILL WHERE ID=" + int.Parse(PurchaseID.Text));

                TextBox Purchase_BillingDate    = (TextBox)CardPurchase.FindControl("Purchase_BillingDate");
                TextBox Purchase_PaymentDate    = (TextBox)CardPurchase.FindControl("Purchase_PaymentDate");
                TextBox Purchase_ExpirationDate = (TextBox)CardPurchase.FindControl("Purchase_ExpirationDate");
                TextBox Purchase_BillNumber     = (TextBox)CardPurchase.FindControl("Purchase_BillNumber");

                TextBox  Purchase_Note    = (TextBox)CardPurchase.FindControl("Purchase_Note");
                CheckBox Purchase_Payment = (CheckBox)CardPurchase.FindControl("Purchase_Payment");
                TextBox  Purchase_ID      = (TextBox)CardPurchase.FindControl("Purchase_ID");

                Purchase_ID.Text             = PurchaseID.Text;
                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=" + int.Parse(PurchaseID.Text));
                ArrayList pp = new ArrayList();
                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);
                }

                Session["newBillProd"] = pp;

                RepeaterPurchaseProduct.DataSource = pp;
                RepeaterPurchaseProduct.DataBind();
                RepeaterPurchaseProduct.Visible = true;

                CardPurchase.Visible     = true;
                RepeaterPurchase.Visible = false;


                break;
            }
        }