Esempio n. 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);
        }
Esempio n. 2
0
        public bool InstallNewLicense()
        {
            OpenFileDialog dlg      = new System.Windows.Forms.OpenFileDialog();
            string         fileName = FindLicenseFile();

            dlg.InitialDirectory = new FileInfo(fileName).DirectoryName;
            dlg.FileName         = fileName;
            dlg.Filter           = "License (" + _LicenseFileName + ")|" + _LicenseFileName +
                                   "|All files (*.*)|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string[] tmp = File.ReadAllLines(dlg.FileName);
                    File.WriteAllLines(LicenseName, tmp);
                    //File.Copy(dlg.FileName, LicenseName, true); // save unmodifyed file
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Can't install new license: " + ex.Message);
                }

                if (LoadLicense())
                {
                    //todo: check activations here
                    currentLicense.SetValue("CPU ID", VWACommon.GetCPUID());
                    //LicenseCipher.SetValue("CPU ID", VWACommon.GetCPUID());
                    currentLicense.SaveLicense(LicenseName);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        public bool CheckLicense()
        {
            string cpu = VWACommon.GetCPUID();

            if (!LicenseManager.IsInited())
            {
                LoadLicense();
            }
            //if (LicenseCipher.IsActivated())
            //{
            string license_cpu = currentLicense.GetValue("CPU ID");

            if (!license_cpu.Equals(cpu) || license_cpu.Trim().Equals(""))
            {
                if (MessageBox.Show("This License was already activated for another CPU.\n Do you want to load another licence?",
                                    "Wrong CPU", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    return(InstallNewLicense());
                }
                return(false);
            }
            return(true);

            //}

            frmEnterActivationCode frm = new frmEnterActivationCode();

            if (frm.ShowDialog() == DialogResult.OK)
            {
                string code = LicenseManager.GenerateActivationCode(cpu, currentLicense.GetValue("License Serial Number"), currentLicense.GetValue("Expiration Date"));
                if (code.Equals(frm.ActivationCode))
                {
                    currentLicense.SetValue("Is Activated", true.ToString());
                    currentLicense.SetValue("Activation Code", code);
                    currentLicense.SetValue("CPU ID", cpu);
                    currentLicense.SaveLicense(LicenseName);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
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());
            }
        }
Esempio n. 5
0
 public frmEnterActivationCode()
 {
     InitializeComponent();
     lblCPUID.Text = VWACommon.GetCPUID();
 }