Example #1
0
        public static string AutoCreateBEOID(string sBEONum, DateTime transferDate, int nTypeCatalogID, ref string sError, System.Data.OleDb.OleDbConnection conn, System.Data.OleDb.OleDbTransaction trans)
        {
            DataTable dt;
            string    sBEOID = "";

            dt = VWA4Common.DB.Retrieve("SELECT TypeID FROM BEOSubTypes " +
                                        " WHERE TypeCatalogID = " + nTypeCatalogID +
                                        " AND Enabled = False " +
                                        " AND TypeID IN (SELECT TypeID FROM BEOType WHERE BEONumber = '" + sBEONum + "')", conn, trans);
            if (nTypeCatalogID != 0 && dt.Rows.Count > 0)// BEO ID Exists but disabled
            {
                sBEOID = dt.Rows[0][0].ToString();
                VWA4Common.DB.Update("UPDATE BEOSubTypes SET Enabled = True WHERE  TypeID = '" + sBEOID + "'", conn, trans);
                sError = (sError == "" ? "" : sError + "\n") + "EO Sub Type was Enabled for this EO Number\n";
                if (dt.Rows.Count > 1)
                {
                    sError = (sError == "" ? "" : sError + "\n") + "More than 1 EO with such EO number exists!\n";
                }
            }
            else
            {
                dt = VWA4Common.DB.Retrieve("SELECT TypeID FROM BEOType " +
                                            " WHERE BEONumber = '" + sBEONum + "'", conn, trans);
                if (dt.Rows.Count > 0) // if BEONumber exists only for master, never happens in correct DB
                {
                    sBEOID = dt.Rows[0][0].ToString();
                    VWA4Common.DB.Insert("INSERT INTO BEOSubTypes (TypeCatalogID, TypeID, Enabled)" +
                                         " VALUES (" + nTypeCatalogID + "'" + dt.Rows[0].ItemArray[0].ToString() + "', True)", conn, trans);
                    sError = (sError == "" ? "" : sError + "\n") + "This BEONumber existed only in master!";
                }
                else
                {
                    sBEOID = GetNextKey("BEOType", conn, trans);
                    int catID = VWA4Common.Utilities.GetQuickAddCategory("BEOCategory", "(Tracker Generated Event Orders)");
                    // create BEOID in master catalog
                    VWA4Common.DB.Insert("INSERT INTO BEOType (TypeID, TypeName, ReportTypeName, EventDate, CatID, BEONumber, ModifiedDate)" +
                                         " VALUES ('" + sBEOID + "', 'AutoGenerated" + sBEONum + "', 'AutoGenerated" + sBEONum + "', #" + VWACommon.DateToString(transferDate) + "#, " +
                                         catID + ", '" +
                                         sBEONum + "', #" + VWACommon.DateToString(DateTime.Now) + "#)", conn, trans);

                    dt = VWA4Common.DB.Retrieve("SELECT ID FROM TypeCatalogs;", conn, trans);
                    string[] arr = new string[dt.Rows.Count];

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string sEnabled = "False";
                        int    currID   = int.Parse(dt.Rows[0].ItemArray[0].ToString());
                        if (currID == nTypeCatalogID)
                        {
                            sEnabled = "True";
                        }
                        // create BEOID in SubTypes
                        VWA4Common.DB.Insert("INSERT INTO BEOSubTypes (TypeCatalogID, TypeID, Enabled)" +
                                             " VALUES (" + currID + ", '" + sBEOID + "', " + sEnabled + ")", conn, trans);
                    }
                }
            }

            return(sBEOID);
        }
Example #2
0
        private static void InitWeightDates()
        {
            DataTable dtWeights = VWA4Common.DB.Retrieve("SELECT MAX(Weights.Timestamp) as  MostRecents, MIN(Weights.Timestamp) as  LeastRecents FROM Weights");
            DataTable dtDates   = VWA4Common.DB.Retrieve("SELECT MAX(WeightDates.Timestamp) as MaxDate, MIN(WeightDates.Timestamp) as MinDate FROM WeightDates");

            if (dtWeights == null || dtWeights.Rows.Count <= 0 || dtDates == null || dtDates.Rows.Count <= 0 ||
                dtDates.Rows[0]["MaxDate"].ToString() == "" ||
                DateTime.Parse(dtDates.Rows[0]["MaxDate"].ToString()) < DateTime.Now ||
                dtWeights.Rows[0]["MostRecents"].ToString() != "" &&
                (DateTime.Parse(dtDates.Rows[0]["MaxDate"].ToString()) < DateTime.Parse(dtWeights.Rows[0]["MostRecents"].ToString()).AddDays(_MinDatesDiff) ||
                 DateTime.Parse(dtDates.Rows[0]["MinDate"].ToString()) > DateTime.Parse(dtWeights.Rows[0]["LeastRecents"].ToString()).AddDays(-_MinDatesDiff)))
            {
                DateTime curr = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                DateTime date, firstdate = curr, lastdate = curr, mindate = curr, maxdate = curr;
                int      diff = 0;

                if (dtWeights != null)
                {
                    if (dtWeights.Rows[0]["LeastRecents"].ToString() != "")
                    {
                        firstdate = DateTime.Parse(dtWeights.Rows[0]["LeastRecents"].ToString());
                    }
                    if (dtWeights.Rows[0]["MostRecents"].ToString() != "")
                    {
                        lastdate = DateTime.Parse(dtWeights.Rows[0]["MostRecents"].ToString());
                    }
                }

                if (dtDates != null)
                {
                    if (dtDates.Rows[0]["MinDate"].ToString() != "")
                    {
                        mindate = DateTime.Parse(dtDates.Rows[0]["MinDate"].ToString());
                    }
                    if (dtDates.Rows[0]["MaxDate"].ToString() != "")
                    {
                        maxdate = DateTime.Parse(dtDates.Rows[0]["MaxDate"].ToString());
                    }
                }

                //_MinDate = date;
                if (dtDates.Rows[0]["MinDate"].ToString() != "")
                {
                    diff = Math.Max(mindate.AddDays(_MinDatesDiff).Subtract(firstdate).Days, 0);
                    date = mindate.AddDays(-diff);
                    for (int i = 0; i < diff; i++)
                    {
                        VWA4Common.DB.Insert("INSERT INTO WeightDates([Timestamp]) VALUES (#" + VWACommon.DateToString(date) + "#)");
                        date = date.AddDays(1);
                    }
                }
                else
                {
                    date = firstdate.AddDays(-_MinDatesDiff);
                    while (date <= firstdate)
                    {
                        VWA4Common.DB.Insert("INSERT INTO WeightDates([Timestamp]) VALUES (#" + VWACommon.DateToString(date) + "#)");
                        date = date.AddDays(1);
                    }
                }

                if (dtDates.Rows[0]["MaxDate"].ToString() != "")
                {
                    date = maxdate.AddDays(1);
                }
                else
                {
                    date = firstdate.AddDays(1);
                }

                while (date < lastdate.AddDays(_MinDatesDiff))
                {
                    VWA4Common.DB.Insert("INSERT INTO WeightDates([Timestamp]) VALUES (#" + VWACommon.DateToString(date) + "#)");
                    date = date.AddDays(1);
                }

                _MostRecents = lastdate;
                //_LeastRecents = firstdate;
                //_MaxDate = date;
            }
            else
            {
                if (dtWeights.Rows[0]["MostRecents"].ToString() != "")
                {
                    _MostRecents = DateTime.Parse(dtWeights.Rows[0]["MostRecents"].ToString());
                }
                //_LeastRecents = DateTime.Parse(dt.Rows[0]["LeastRecents"].ToString());
                //_MaxDate = DateTime.Parse(dt.Rows[0]["MaxDate"].ToString());
                //_MinDate = DateTime.Parse(dt.Rows[0]["MinDate"].ToString());
            }
        }