Beispiel #1
0
        public void MetaData_BeforePost()
        {
            SM = null;
            if (DS.storeunload.Rows.Count == 0)
            {
                return;
            }
            DataRow Curr = DS.storeunload.Rows[0];

            if (Curr.RowState == DataRowState.Deleted)
            {
                idrelated  = GetIdForDocument(DS.storeunload.Rows[0]);
                fromDelete = true;
            }
            else
            {
                SM = new StoreUnloadSendMail(Conn);
                SM.PrepareMailToSend(DS);
            }
        }
Beispiel #2
0
        void ScaricaPrenotazione(DataAccess Conn, string idbooking)
        {
            vistaform_storeunload_magazzino DS = new vistaform_storeunload_magazzino();
            CQueryHelper QHC = new CQueryHelper();

            QueryHelper QHS = Conn.GetQueryHelper();

            //WebLog.Log(this, "Visualizza Login_Servizi");
            object Obooking_on_invoice = Conn.DO_READ_VALUE("config", QHS.CmpEq("ayear", Conn.GetSys("esercizio")), "booking_on_invoice");

            if (Obooking_on_invoice == null || Obooking_on_invoice == DBNull.Value || Obooking_on_invoice.ToString() == "")
            {
                Obooking_on_invoice = "N";
            }
            Obooking_on_invoice = Obooking_on_invoice.ToString().ToUpper();
            bool booking_on_invoice = (Obooking_on_invoice.ToString() == "S");



            DataTable BookingToUnload = Conn.RUN_SELECT("booktotalview", "*", null,
                                                        QHS.AppAnd(QHS.CmpGt("allocated", 0), QHS.CmpEq("idbooking", idbooking)), null, true);

            DataTable TStockView = Conn.CreateTableByName("stockview", "*");

            TStockView.PrimaryKey = new DataColumn[] { TStockView.Columns["idstock"] };

            Meta_EasyDispatcher Disp = new Meta_EasyDispatcher(Conn);

            MetaData MetaStoreUnload = Disp.Get("storeunload");

            MetaStoreUnload.SetDefaults(DS.storeunload);
            MetaData MetaStoreUnloadDetail = Disp.Get("storeunloaddetail");

            MetaStoreUnloadDetail.SetDefaults(DS.storeunloaddetail);


            DataRow[] Selected = BookingToUnload.Select();
            if (Selected.Length == 0)
            {
                //niente da scaricare
                lblMessaggio.Text = "Non c'è nulla da scaricare";
                txtCodice.Text    = "";
                return;
            }

            DataRow RStoreUnload = MetaStoreUnload.Get_New_Row(null, DS.storeunload);

            RStoreUnload["description"] = "Scarico prenotazione da magazzino";
            RStoreUnload["idstore"]     = Selected[0]["idstore"];
            RStoreUnload["adate"]       = DateTime.Now;

            Hashtable idlistToStock = new Hashtable();//l'elemento della hashtable è un list<int>

            //Prende una riga di prenotazione
            foreach (DataRow R in Selected)    // riga di prenotazione
            {
                string filterbooking       = QHS.CmpEq("idbooking", R["idbooking"]);
                string filterbookingdetail = QHS.AppAnd(filterbooking,
                                                        QHS.CmpEq("idlist", R["idlist"]));

                DataTable B     = Conn.RUN_SELECT("bookingdetail", "*", null, filterbookingdetail, null, false);
                DataTable Bmain = Conn.RUN_SELECT("booking", "*", null, filterbooking, null, false);

                DataRow BookingDetail = null;


                string filterstock = QHS.AppAnd(QHS.CmpEq("idstore", R["idstore"]),
                                                QHS.CmpEq("idlist", R["idlist"]),
                                                QHS.CmpGt("residual", 0));
                string filterstockds = QHC.AppAnd(QHC.CmpEq("idstore", R["idstore"]),
                                                  QHC.CmpEq("idlist", R["idlist"]),
                                                  QHC.CmpGt("residual", 0));


                //legge in TStockView i cespiti di stock disponibili ad essere scaricati

                if (booking_on_invoice)
                {
                    filterstock   = QHS.AppAnd(filterstock, QHS.CmpEq("idstock", R["idstock"]));
                    filterstockds = QHC.AppAnd(filterstockds, QHC.CmpEq("idstock", R["idstock"]));
                }

                if (TStockView.Select(filterstockds).Length == 0)
                {
                    Conn.RUN_SELECT_INTO_TABLE(TStockView, "expiry asc, idstock asc", filterstock, null, true);
                }

                ///SViewRows = cespiti disponibili (da stockview) allo scarico
                DataRow[] SViewRows = TStockView.Select(filterstockds);
                if (SViewRows.Length == 0)
                {
                    continue;
                }

                DataRow RS;
                decimal tounload = CfgFn.GetNoNullDecimal(R["allocated"]);

                int i = 0;
                //Cerca di scaricare prendendo le righe in SViewRows
                while (i < SViewRows.Length && tounload > 0)
                {
                    DataRow RStock     = SViewRows[i];
                    decimal unloadable = CfgFn.GetNoNullDecimal(RStock["residual"]);
                    if (unloadable > tounload)
                    {
                        unloadable = tounload;
                    }
                    //devo scaricare unloadable
                    string fbooking = filterbooking;


                    //devo scaricare unloadable
                    fbooking = QHC.AppAnd(fbooking, QHC.CmpEq("idstock", RStock["idstock"]));

                    //cerca una riga in storeunloaddetail di pari idstock e idbooking (idstock è sempre noto a questo punto)
                    if (DS.storeunloaddetail.Select(fbooking).Length > 0)
                    {
                        RS           = DS.storeunloaddetail.Select(fbooking)[0];
                        RS["number"] = CfgFn.GetNoNullDecimal(RS["number"]) + unloadable;
                    }
                    else
                    {
                        RS              = MetaStoreUnloadDetail.Get_New_Row(DS.storeunload.Rows[0], DS.storeunloaddetail);
                        RS["number"]    = unloadable;
                        RS["idbooking"] = R["idbooking"];
                        // Determino idstock
                        // io ho una serie di di idlist e idstore
                        // in base ai dettagli selezionati mi servono
                        // per accedere alla vista delle giacenze di stock e creo
                        // una tabella che deve essere filtrata per idlist
                        // idstore e giacenza > 0
                        RS["idstock"] = RStock["idstock"];//T.Rows[0]["idstock"];
                        if (B.Rows.Count > 0)
                        {
                            BookingDetail = B.Rows[0];
                            RS["idsor1"]  = BookingDetail["idsor1"];
                            RS["idsor2"]  = BookingDetail["idsor2"];
                            RS["idsor3"]  = BookingDetail["idsor3"];
                            RS["idman"]   = Bmain.Rows[0]["idman"];
                        }
                    }
                    tounload          -= unloadable;
                    RStock["residual"] = CfgFn.GetNoNullDecimal(RStock["residual"]) - unloadable;
                    i++;
                }
            }
            StoreUnloadSendMail SUSM = new StoreUnloadSendMail(Conn);

            SUSM.PrepareMailToSend(DS);

            Easy_PostData EP = new Easy_PostData();

            EP.InitClass(DS, Conn);
            ProcedureMessageCollection PC = EP.DO_POST_SERVICE();

            if (PC.Count > 0)
            {
                string err = "";
                foreach (EasyProcedureMessage PM in PC)
                {
                    err += PM.AuditID + "/" + PM.TableName + "/" + PM.Operation + "/" + PM.EnforcementNumber + "(" + PM.LongMess + ") ";
                }
                string data = "";
                foreach (DataRow r in DS.storeunloaddetail.Rows)
                {
                    data += "[idstock=" + r["idstock"].ToString() + ",number=" + r["number"].ToString() + ",idbooking=" + r["idbooking"].ToString() +
                            ",idman=" + r["idman"].ToString() + "] ";
                }
                lblMessaggio.Text = "Errore in fase di salvataggio dati: " + err + " Data: " + data;
                GetVars.ClearUserConn(this);
            }
            else
            {
                EP.DO_POST_SERVICE();
                DataRow Curr = DS.storeunload.Rows[0];
                StampaReport(Conn, CfgFn.GetNoNullInt32(Curr["idstoreunload"]));
                SUSM.SendMail();
                lblMessaggio.Text = "Scarico effettuato.";
                txtCodice.Text    = "";
            }
        }