Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ArrayList pp = Rowediting1.ProductRows();

            if (pp.Count > 0)
            {
                bool newQuote;

                long billId;
                using (DigiDapter dg = new DigiDapter())
                {
                    dg.Add("OWNERID", this.TextboxSearchOwnerID.Text);
                    if (this.TextboxSearchManagerID.Text.Length > 0)
                    {
                        dg.Add("MANAGERID", this.TextboxSearchManagerID.Text);
                    }
                    if (this.TextboxSearchSignalerID.Text.Length > 0)
                    {
                        dg.Add("SIGNALER", this.TextboxSearchSignalerID.Text);
                    }
                    dg.Add("SUBJECT", this.QSubject.Text);
                    dg.Add("DESCRIPTION", this.QuoteDescription.Text);
                    dg.Add("CURRENCY", Rowediting1.RowEstCurrency);
                    dg.Add("CHANGE", StaticFunctions.FixDecimal(Rowediting1.RowEstChange));
                    DateTime ExpirationDate;
                    try
                    {
                        ExpirationDate = UC.LTZ.ToUniversalTime(Convert.ToDateTime(QValidData.Text));
                    }
                    catch
                    {
                        ExpirationDate = DateTime.Now.AddDays(30);
                    }
                    dg.Add("EXPIRATIONDATE", ExpirationDate);

                    DateTime QuoteDate;
                    try
                    {
                        QuoteDate = UC.LTZ.ToUniversalTime(Convert.ToDateTime(QuoteData.Text));
                    }
                    catch
                    {
                        QuoteDate = DateTime.Now;
                    }
                    dg.Add("QUOTEDATE", QuoteDate);

                    if (ShipDescription.SelectedIndex > 0)
                    {
                        dg.Add("SHIPID", ShipDescription.SelectedValue.Split('|')[0]);
                    }

                    if (ShipData.Text.Length > 0)
                    {
                        dg.Add("SHIPDATE", UC.LTZ.ToUniversalTime(Convert.ToDateTime(ShipData.Text)));
                    }

                    dg.Add("LASTMODIFIEDDATE", DateTime.Now);
                    dg.Add("LASTMODIFIEDBYID", UC.UserId);

                    if (this.QuoteID == -1)
                    {
                        dg.Add("CREATEDBYID", UC.UserId);
                    }

                    dg.Add("ACTIVITYID", this.ActivityID);
                    if (this.QStage.SelectedValue == "-1")
                    {
                        dg.Add("STAGE", ((int)QuoteStage.Negotiation).ToString());
                    }
                    else
                    {
                        dg.Add("STAGE", this.QStage.SelectedValue);
                    }
                    dg.Add("PAYMENTID", this.QPayment.SelectedValue);
                    Object progressive;
                    progressive = DatabaseConnection.SqlScalartoObj("SELECT DISABLED FROM QUOTENUMBERS WHERE TYPE=0");
                    if (progressive != null && !((bool)progressive))
                    {
                        DataRow drprog;

                        drprog = DatabaseConnection.CreateDataset("SELECT * FROM QUOTENUMBERS WHERE TYPE=0").Tables[0].Rows[0];
                        string newprog = string.Empty;

                        if (Convert.ToInt32(drprog["NPROGRESTART"]) > 0)
                        {
                            if (DateTime.Now >= new DateTime(DateTime.Now.Year, Convert.ToInt32(drprog["NPROGRESTART"]), 1) && new DateTime(DateTime.Now.Year, Convert.ToInt32(drprog["NPROGRESTART"]), 1) >= (DateTime)drprog["LASTRESET"])
                            {
                                DatabaseConnection.DoCommand("UPDATE QUOTENUMBERS SET NPROG=NPROGSTART,LASTRESET=GETDATE() WHERE TYPE=0");
                                drprog = DatabaseConnection.CreateDataset("SELECT * FROM QUOTENUMBERS WHERE TYPE=0").Tables[0].Rows[0];
                            }
                        }
                        newprog += (((int)drprog["NPROG"]) + 1).ToString();
                        if ((bool)drprog["CHECKDAY"])
                        {
                            newprog += "-" + DateTime.Now.Day.ToString();
                        }
                        if ((bool)drprog["CHECKMONTH"])
                        {
                            newprog += "-" + DateTime.Now.Month.ToString();
                        }
                        if ((bool)drprog["CHECKYEAR"])
                        {
                            if ((bool)drprog["TWODIGITYEAR"])
                            {
                                newprog += "-" + DateTime.Now.ToString("yyyy");
                            }
                            else
                            {
                                newprog += "-" + DateTime.Now.ToString("yy");
                            }
                        }

                        if ((bool)drprog["CHECKCUSTOMERCODE"])
                        {
                            switch (CrossWith.SelectedIndex)
                            {
                            case 0:
                                newprog += "-" + DatabaseConnection.SqlScalar("SELECT COMPANYCODE FROM BASE_COMPANIES WHERE ID=" + CrossWithID.Text);
                                break;

                            case 1:

                                break;

                            case 2:

                                break;
                            }
                        }

                        this.Qnumber.Text = newprog;
                        DatabaseConnection.DoCommand("UPDATE QUOTENUMBERS SET NPROG=NPROG+1 WHERE TYPE=0");
                    }

                    if (this.Qnumber.Text.Length > 0)
                    {
                        dg.Add("NUMBER", this.Qnumber.Text);
                    }

                    dg.Add("REDUCTION", 0);

                    dg.Add("CROSSTYPE", CrossWith.SelectedValue);
                    dg.Add("CROSSID", CrossWithID.Text);
                    dg.Add("ADDRESS", QAddress.Text);
                    dg.Add("SHIPADDRESS", SAddress.Text);


                    dg.Add("GRANDTOTAL", Convert.ToDecimal(Request["grandtotal"]));
                    dg.Add("SUBTOTAL", Convert.ToDecimal(Request["subtotal"]));
                    dg.Add("TAXTOTAL", Convert.ToDecimal(Request["taxtotal"]));
                    dg.Add("SHIP", (Request["shiptotal"].Length > 0)?Convert.ToDecimal(Request["shiptotal"]):0);
                    dg.Add("SHIPVAT", (Request["shipVat"].Length > 0)?Convert.ToDecimal(Request["shipVat"]):0);

                    dg.Add("GROUPS", "|" + UC.UserGroupId.ToString() + "|");

                    dg.Add("INCLUDEPRODPDF", (chkIncludePDFDoc.Checked)?1:0);
                    dg.Add("LIST", currentPriceList.Text);

                    billId = Convert.ToInt64(dg.Execute("QUOTES", "id=" + this.QuoteID, DigiDapter.Identities.Identity));
                    if (this.QuoteID == -1)
                    {
                        this.QuoteID = Convert.ToInt64(billId);
                    }
                    newQuote = dg.RecordInserted;
                }
                if (!newQuote)
                {
                    DatabaseConnection.DoCommand("DELETE FROM QUOTEROWS WHERE ESTIMATEID=" + this.QuoteID);
                    DatabaseConnection.DoCommand("DELETE FROM QUOTEDOCUMENT WHERE QUOTEID=" + this.QuoteID);
                }
                foreach (PurchaseProduct Pprod in pp)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("ESTIMATEID", this.QuoteID);
                        dg.Add("DESCRIPTION", Pprod.ShortDescription);
                        dg.Add("DESCRIPTION2", Pprod.LongDescription);
                        dg.Add("UPRICE", Pprod.UnitPrice);
                        dg.Add("NEWUPRICE", Pprod.FinalPrice);
                        dg.Add("LISTPRICE", Pprod.ListPrice);
                        dg.Add("CATALOGID", Pprod.id);
                        dg.Add("QTA", Pprod.Qta);
                        dg.Add("REDUCTION", Pprod.Reduction);
                        dg.Add("TAX", Pprod.Vat);
                        dg.Add("COST", Pprod.Cost);
                        dg.Add("PRODUCTCODE", Pprod.ProductCode);
                        dg.Add("REALLISTPRICE", Pprod.RealListPrice);
                        dg.Execute("QUOTEROWS");
                    }
                }
                if (Request["IDDocument"] != null && Request["IDDocument"].ToString().Length > 0)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("QUOTEID", this.QuoteID);
                        dg.Add("DOCUMENTID", Convert.ToInt64(Request["IDDocument"]));
                        dg.Execute("QUOTEDOCUMENT");
                    }
                }

                int otherdocument = 1;
                while (Request["IDDocument_" + otherdocument] != null && Request["IDDocument_" + otherdocument].ToString().Length > 0)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("QUOTEID", this.QuoteID);
                        dg.Add("DOCUMENTID", Convert.ToInt64(Request["IDDocument_" + otherdocument]));
                        dg.Execute("QUOTEDOCUMENT");
                    }
                    otherdocument++;
                }

                ClientScript.RegisterStartupScript(this.GetType(), "OK", "<script>alert('" + string.Format(Root.rm.GetString("Esttxt19"), this.Qnumber.Text) + "');location.href='/erp/quotelist.aspx?m=67&dgb=1&si=69';</script>");
                FillQuote(this.QuoteID);

                if (CheckActivity.Checked && CrossWithID.Text.Length > 0)
                {
                    ActivityInsert ai = new ActivityInsert();
                    string         A  = "";
                    string         C  = "";
                    string         L  = "";

                    switch (CrossWith.SelectedValue)
                    {
                    case "0":
                        A = CrossWithID.Text;
                        C = "";
                        L = "";
                        break;

                    case "1":
                        C = CrossWithID.Text;
                        A = "";
                        L = "";
                        break;

                    case "2":
                        L = CrossWithID.Text;
                        A = "";
                        C = "";
                        break;
                    }
                    if (A.Length > 0 || C.Length > 0 || L.Length > 0)
                    {
                        ai.InsertActivity("7", "", UC.UserId.ToString(), C, A, L, Root.rm.GetString("Esttxt2") + ":" + this.QSubject.Text, this.QuoteDescription.Text, UC.LTZ.ToUniversalTime(DateTime.Now), UC, 1);
                    }
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "OK", "<script>alert('" + Root.rm.GetString("Quotxt29") + "');</script>");
            }
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ArrayList pp = Rowediting1.ProductRows();

            if (pp.Count > 0)
            {
                bool newQuote;

                long billId;
                using (DigiDapter dg = new DigiDapter())
                {
                    dg.Add("OWNERID", this.TextboxSearchOwnerID.Text);
                    if (this.TextboxSearchManagerID.Text.Length > 0)
                    {
                        dg.Add("MANAGERID", this.TextboxSearchManagerID.Text);
                    }
                    if (this.TextboxSearchSignalerID.Text.Length > 0)
                    {
                        dg.Add("SIGNALER", this.TextboxSearchSignalerID.Text);
                    }
                    dg.Add("SUBJECT", this.QSubject.Text);
                    dg.Add("DESCRIPTION", this.QuoteDescription.Text);
                    dg.Add("CURRENCY", Rowediting1.RowEstCurrency);
                    dg.Add("CHANGE", StaticFunctions.FixDecimal(Rowediting1.RowEstChange));
                    DateTime ExpirationDate;
                    try
                    {
                        ExpirationDate = UC.LTZ.ToUniversalTime(Convert.ToDateTime(QValidData.Text));
                    }
                    catch
                    {
                        ExpirationDate = DateTime.Now.AddDays(30);
                    }
                    dg.Add("EXPIRATIONDATE", ExpirationDate);

                    DateTime QuoteDate;
                    try
                    {
                        QuoteDate = UC.LTZ.ToUniversalTime(Convert.ToDateTime(QuoteData.Text));
                    }
                    catch
                    {
                        QuoteDate = DateTime.Now;
                    }
                    dg.Add("QUOTEDATE", QuoteDate);

                    if (ShipDescription.SelectedIndex > 0)
                    {
                        dg.Add("SHIPID", ShipDescription.SelectedValue.Split('|')[0]);
                    }

                    if (ShipData.Text.Length > 0)
                    {
                        dg.Add("SHIPDATE", UC.LTZ.ToUniversalTime(Convert.ToDateTime(ShipData.Text)));
                    }

                    dg.Add("LASTMODIFIEDDATE", DateTime.Now);
                    dg.Add("LASTMODIFIEDBYID", UC.UserId);

                    if (this.QuoteID == -1)
                    {
                        dg.Add("CREATEDBYID", UC.UserId);
                    }

                    dg.Add("ACTIVITYID", this.ActivityID);
                    if (this.QStage.SelectedValue == "-1")
                    {
                        dg.Add("STAGE", ((int)QuoteStage.Negotiation).ToString());
                    }
                    else
                    {
                        dg.Add("STAGE", this.QStage.SelectedValue);
                    }
                    dg.Add("PAYMENTID", this.QPayment.SelectedValue);
                    if (this.Qnumber.Text.Length > 0)
                    {
                        dg.Add("NUMBER", this.Qnumber.Text);
                    }

                    dg.Add("REDUCTION", 0);

                    dg.Add("CROSSTYPE", CrossWith.SelectedValue);
                    dg.Add("CROSSID", CrossWithID.Text);
                    dg.Add("ADDRESS", QAddress.Text);
                    dg.Add("SHIPADDRESS", SAddress.Text);


                    dg.Add("GRANDTOTAL", Convert.ToDecimal(Request["grandtotal"]));
                    dg.Add("SUBTOTAL", Convert.ToDecimal(Request["subtotal"]));
                    dg.Add("TAXTOTAL", Convert.ToDecimal(Request["taxtotal"]));
                    dg.Add("SHIP", (Request["shiptotal"].Length > 0)?Convert.ToDecimal(Request["shiptotal"]):0);
                    dg.Add("SHIPVAT", (Request["shipVat"].Length > 0)?Convert.ToDecimal(Request["shipVat"]):0);

                    dg.Add("GROUPS", "|" + UC.UserGroupId.ToString() + "|");

                    dg.Add("INCLUDEPRODPDF", (chkIncludePDFDoc.Checked)?1:0);

                    billId = Convert.ToInt64(dg.Execute("ORDERS", "ID=" + this.QuoteID, DigiDapter.Identities.Identity));
                    if (this.QuoteID == -1)
                    {
                        this.QuoteID = Convert.ToInt64(billId);
                    }
                    newQuote = dg.RecordInserted;
                }

                if (InvoiceNumber.Text.Length > 0)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("ORDERID", this.QuoteID);
                        DateTime invoiceDate;
                        try
                        {
                            invoiceDate = UC.LTZ.ToUniversalTime(Convert.ToDateTime(InvoiceDate.Text));
                        }
                        catch
                        {
                            try
                            {
                                invoiceDate = UC.LTZ.ToUniversalTime(Convert.ToDateTime(QuoteData.Text));
                            }
                            catch
                            {
                                invoiceDate = DateTime.Now;
                            }
                        }
                        dg.Add("INVOICEDATE", invoiceDate);
                        dg.Add("INVOICENUMBER", InvoiceNumber.Text);
                        if (InvoiceExpirationDate.Text.Length > 0)
                        {
                            dg.Add("EXPIRATIONDATE", UC.LTZ.ToUniversalTime(Convert.ToDateTime(InvoiceExpirationDate.Text)));
                        }
                        if (InvoicePaymentDate.Text.Length > 0)
                        {
                            dg.Add("PAYMENTDATE", UC.LTZ.ToUniversalTime(Convert.ToDateTime(InvoicePaymentDate.Text)));
                        }
                        dg.Add("PAID", InvoicePaid.Checked);
                        dg.Execute("INVOICES", "ID=" + InvoiceId.Text);
                    }
                }

                if (!newQuote)
                {
                    DatabaseConnection.DoCommand("DELETE FROM ORDERROWS WHERE ORDERID=" + this.QuoteID);
                    DatabaseConnection.DoCommand("DELETE FROM ORDERDOCUMENT WHERE ORDERID=" + this.QuoteID);
                }
                foreach (PurchaseProduct Pprod in pp)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("ORDERID", this.QuoteID);
                        dg.Add("DESCRIPTION", Pprod.ShortDescription);
                        dg.Add("DESCRIPTION2", Pprod.LongDescription);
                        dg.Add("UPRICE", Pprod.UnitPrice);
                        dg.Add("NEWUPRICE", Pprod.FinalPrice);
                        dg.Add("LISTPRICE", Pprod.ListPrice);
                        dg.Add("CATALOGID", Pprod.id);
                        dg.Add("QTA", Pprod.Qta);
                        dg.Add("REDUCTION", Pprod.Reduction);
                        dg.Add("TAX", Pprod.Vat);
                        dg.Add("COST", Pprod.Cost);
                        dg.Add("REALLISTPRICE", Pprod.RealListPrice);
                        dg.Execute("ORDERROWS");
                    }
                }
                if (Request["IDDocument"] != null && Request["IDDocument"].ToString().Length > 0)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("QUOTEID", this.QuoteID);
                        dg.Add("DOCUMENTID", Convert.ToInt64(Request["IDDocument"]));
                        dg.Execute("ORDERDOCUMENT");
                    }
                }

                int otherdocument = 1;
                while (Request["IDDocument_" + otherdocument] != null && Request["IDDocument_" + otherdocument].ToString().Length > 0)
                {
                    using (DigiDapter dg = new DigiDapter())
                    {
                        dg.Add("QUOTEID", this.QuoteID);
                        dg.Add("DOCUMENTID", Convert.ToInt64(Request["IDDocument_" + otherdocument]));
                        dg.Execute("ORDERDOCUMENT");
                    }
                    otherdocument++;
                }

                ClientScript.RegisterStartupScript(this.GetType(), "OK", "<script>alert('" + string.Format(Root.rm.GetString("Ordtxt11"), this.Qnumber.Text) + "');location.href='/erp/orderlist.aspx?m=67&dgb=1&si=69';</script>");
                FillQuote(this.QuoteID);

                if (CheckActivity.Checked && CrossWithID.Text.Length > 0)
                {
                    ActivityInsert ai = new ActivityInsert();
                    string         A  = "";
                    string         C  = "";
                    string         L  = "";

                    switch (CrossWith.SelectedValue)
                    {
                    case "0":
                        A = CrossWithID.Text;
                        C = "";
                        L = "";
                        break;

                    case "1":
                        C = CrossWithID.Text;
                        A = "";
                        L = "";
                        break;

                    case "2":
                        L = CrossWithID.Text;
                        A = "";
                        C = "";
                        break;
                    }
                    if (A.Length > 0 || C.Length > 0 || L.Length > 0)
                    {
                        ai.InsertActivity("7", "", UC.UserId.ToString(), C, A, L, Root.rm.GetString("Ordtxt12") + ":" + this.QSubject.Text, this.QuoteDescription.Text, UC.LTZ.ToUniversalTime(DateTime.Now), UC, 1);
                    }
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "OK", "<script>alert('" + Root.rm.GetString("Quotxt29") + "');</script>");
            }
        }