Example #1
0
    public static string GetMysqlDatabaseField(string field, string key, int keyValue, string table)
    {
        string entry;

        ADODB.Connection conn = new ADODB.Connection();
        ADODB.Recordset  rec  = new ADODB.Recordset();

        bool   adoOpened     = DbUse.OpenAdoMysql(conn);
        string commandString = "SELECT " + key + ", " + field + " FROM " + table + " WHERE " + key + " = " + keyValue + ";";
        bool   adoRecOpened  = DbUse.OpenAdoRec(conn, rec, commandString);

        if (!adoOpened || !adoRecOpened)
        {
            throw new Exception("Error in opening database/dataset.");
        }

        try {
            entry = rec.Fields[field].Value.ToString();
        } catch (Exception) {
            throw new Exception("Field '" + field + "' not found in the table '" + table + "'.");
        }
        DbUse.CloseAdo(conn);
        DbUse.CloseAdoRec(rec);
        return(entry);
    }
Example #2
0
    } // end sub;

    float availtime()
    {
        //on error GoTo err_availtime;

        ADODB.Recordset reccust = null;
        float           X;

        DbUse.open_ado_rec(globaldb, ref reccust, "tblgeneral");

        X = ((float)reccust.Fields["RTU1b"].Value) * ((float)reccust.Fields["RTU1c"].Value);
        if ((X <= 0))
        {
            X = 1;
        }
        ;



        //exit_availtime:
        DbUse.CloseAdoRec(reccust);
        reccust = null;
        return(X); //exit  Function;

        //err_availtime:
        // msgbox(ErrorToString(), 0, appl_name);
        // resume  exit_availtime;
    } // end function;
Example #3
0
    protected bool WhatifExists(string whatifName)
    {
        bool exists = false;

        ADODB.Recordset rec = new ADODB.Recordset();
        DbUse.OpenAdoRec(classE1_1.globaldb, rec, "SELECT WID, Name FROM tblWhatif;");
        try {
            int i = 0;
            while (!rec.EOF && !exists)
            {
                if (i == 0)
                {
                    rec.MoveFirst();
                }
                else
                {
                    rec.MoveNext();
                }
                exists = rec.Fields["Name"].Value.ToString().ToUpper().Equals(whatifName.ToUpper());
                i++;
            }
        } catch (Exception) { }
        DbUse.CloseAdoRec(rec);
        return(exists);
    }
    public static bool SameOperNumDiffNameExists(string opName, int opNum, int prodId, int opId, string connectionString, LogFiles logFiles)
    {
        bool exists = false;

        ADODB.Connection conn = new ADODB.Connection();
        ADODB.Recordset  rec  = new ADODB.Recordset();

        opName = opName.ToUpper();

        bool   adoOpen     = DbUse.OpenAdo(conn, connectionString);
        string queryString = "SELECT OpID, OpNam, OpNum, Prodfore FROM tblOper WHERE Prodfore = " + prodId + " AND OpNam <> '" + opName + "' AND OpNum = " + opNum + " AND OpID <> " + opId;
        bool   recOpen     = DbUse.OpenAdoRec(conn, rec, queryString);

        try {
            if (adoOpen && recOpen)
            {
                exists = !rec.EOF;
            }
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
        } finally {
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
        }
        return(exists);
    }
Example #5
0
    } // end function;

    public string Get_whatif_comment(int wid)
    {
        //on error GoTo Err_Get_whatif_name;

        ADODB.Recordset recset1 = null;
        string          retval;

        if (wid == 0)
        {
            retval = "Base Case";
        }
        else
        {
            DbUse.open_ado_rec(globaldb, ref recset1, "tblwhatif");
            recset1.Filter = "[wid] =" + wid;
            retval         = (string)recset1.Fields["Comm"].Value;
            DbUse.CloseAdoRec(recset1);
            recset1 = null;
        };

        // return; //exit _Get_whatif_name:
        return(retval);  //exit  Function;

        //Err_Get_whatif_name:
        // msgbox(ErrorToString(), 0, appl_name);
        //RESUME NEXT
    } // end function;
    /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public int has_group_leader(string groupname, string username)
    /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    {
        try {
            string           entry;
            ADODB.Connection conn = new ADODB.Connection();
            ADODB.Recordset  rec  = new ADODB.Recordset();

            bool adoOpened = DbUse.OpenAdoMysql(conn);



            string commandString = "SELECT `webmpx`.group_members.* FROM   `webmpx`.group_members  WHERE (((`webmpx`.group_members.Groupname)='" + groupname + "') AND ((`webmpx`.group_members.Username)='" + username + "')  and (`webmpx`.Group_members.Leader = 'yes')  ); ";

            bool adoRecOpened = DbUse.OpenAdoRec(conn, rec, commandString);
            if (!adoOpened || !adoRecOpened)
            {
                throw new Exception("Error in opening database/dataset.");
            }

            try {
                entry = rec.Fields["leader"].Value.ToString();
            } catch (Exception) {
                throw new Exception("Field  username  leader  not found in the table  group_members.");
            }  //  end try
            DbUse.CloseAdo(conn);
            DbUse.CloseAdoRec(rec);
        } catch (Exception ex) {
            if (ex.Message.IndexOf("not found") >= 0)
            {
                return(0);
            }
        } //  end try
        return(-1);  //  group leader set ='yes'
    }     //  end routine
    protected void ReadData()
    {
        bool   adoOpened     = DbUse.open_ado(ref conn, GetDirectory() + userDir + MAIN_USER_DATABASE);
        string commandString = "SELECT " + TBL_GENERAL + ".* FROM(" + TBL_GENERAL + ");";
        bool   adoRecOpened  = DbUse.open_ado_rec(conn, ref rec, commandString);

        try {
            if (!adoOpened || !adoRecOpened)
            {
                throw new Exception("Error in opening database/dataset. The data cannot be displayed.");
            }
            try {
                string title = (string)rec.Fields["Title"].Value;
                title1.Value  = title;
                comment.Value = rec.Fields["com"].Value.ToString();
                dtu.Text      = (string)rec.Fields["TUFor"].Value;
                mcttu.Text    = (string)rec.Fields["tult"].Value;
                optu.Text     = (string)rec.Fields["tuprod"].Value;

                cv1.Text = rec.Fields["RTU1b"].Value.ToString();
                cv2.Text = rec.Fields["RTU1c"].Value.ToString();

                utlimit.Text = rec.Fields["Utlimit"].Value.ToString();
                laborcv.Text = rec.Fields["coef_v_labor"].Value.ToString();
                equipcv.Text = rec.Fields["coef_v_equip"].Value.ToString();
                partcv.Text  = rec.Fields["coef_v_parts"].Value.ToString();
            } catch (Exception) {
                Master.ShowErrorMessage("An error has occured while reading the data from the database. Some data might not display correctly.");
            }
        } catch (Exception ex) {
            Master.ShowErrorMessage(ex.Message);
        }
        DbUse.CloseAdo(conn);
        DbUse.CloseAdoRec(rec);
    }
Example #8
0
    public string Get_whatif_name(int wid)
    {
        //on error GoTo Err_Get_whatif_name;

        ADODB.Recordset recset1 = null;
        string          retval;

        if (wid == 0)
        {
            retval = "Basecase";
        }
        else
        {
            DbUse.open_ado_rec(globaldb, ref recset1, "Select tblwhatif.* from tblwhatif where wid = " + wid + ";");
            if (recset1.EOF)
            {
                retval = "";
            }
            else
            {
                retval = (string)recset1.Fields["Name"].Value;
            }

            DbUse.CloseAdoRec(recset1);
            recset1 = null;
        };

        return(retval);  //exit  Function;

        //Err_Get_whatif_name:
        // msgbox(ErrorToString(), 0, appl_name);
        //RESUME NEXT
    } // end function;
Example #9
0
    } // end function;

    public int testresetwid(int wid)
    {
        ADODB.Recordset recset1 = null;
        int             retval;

        if (wid == 0)
        {
            retval = -1;
            return(retval);
        }
        DbUse.open_ado_rec(globaldb, ref recset1, "Select tblwhatif.* from tblwhatif where wid = " + wid + ";");
        if (!recset1.EOF)
        {
            retval = -1;
        }
        else
        {
            retval  = 0;
            glngwid = 0;     //  !!!  reset to 0 basecase !!
            saveWid();
            saveRecalcNeeded(0, -1);
            model_modified = -1;
            saveModel_modified();
        }

        DbUse.CloseAdoRec(recset1);
        recset1 = null;

        return(retval);
    }
Example #10
0
    } // end function;

    public long Get_whatif_wid(string whatifname)
    {
        //on error GoTo Err_Get_whatif_name;

        ADODB.Recordset recset1 = null;
        long            retval;

        if (whatifname == "Base Case")
        {
            return(0);
        }

        else
        {
            DbUse.open_ado_rec(globaldb, ref recset1, "Select tblwhatif.* from tblwhatif where name = " + whatifname + ";");
            if (recset1.EOF)
            {
                retval = -1;
            }
            else
            {
                retval = (long)recset1.Fields["wid"].Value;
            }

            DbUse.CloseAdoRec(recset1);
            recset1 = null;
        };

        return(retval); //exit  Function;
    } // end function;
Example #11
0
    public bool ChangeEmail(string cookieid, string email)
    {
        bool   updated   = false;
        string sqlString = "SELECT usercred.id, usercred.mail FROM usercred INNER JOIN userlist ON usercred.id = userlist.id WHERE userlist.sessionid = '" + cookieid + "';";

        conn = new ADODB.Connection();
        rec  = new ADODB.Recordset();
        bool openedCon = DbUse.OpenAdoMysql(conn);
        bool openedRec = DbUse.OpenAdoRec(conn, rec, sqlString);

        try {
            if (!openedCon || !openedRec)
            {
                throw new Exception("An error has occured. Please try again.");
            }
            else if (rec.EOF)
            {
                throw new Exception("An internal error has occured. Missing data.");
            }
            else
            {
                rec.Fields["mail"].Value = email;
                rec.Update();
                updated = true;
            }
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
            Master.ShowErrorMessage(ex.Message);
        } finally {
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
        }

        return(updated);
    }
Example #12
0
    public static string Progress(string sessionID)
    {
        var returnable = "";


        ADODB.Connection conn = new ADODB.Connection();
        ADODB.Recordset  rec  = new ADODB.Recordset();

        int    timePerCalc = -1;
        int    total       = -1;
        int    calc        = -1;
        string myName      = "";



        bool   adoOpened     = DbUse.OpenAdoMysql(conn);
        string commandString = "SELECT usercalc.id, usercalc.total, usercalc.calc, usercalc.timePerCalc, userCalc.curName, userlist.sessionid FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + sessionID + "';";
        bool   adoRecOpened  = DbUse.OpenAdoRec(conn, rec, commandString);

        try
        {
            timePerCalc = int.Parse(rec.Fields["timePerCalc"].Value.ToString());
            total       = int.Parse(rec.Fields["total"].Value.ToString());
            calc        = int.Parse(rec.Fields["calc"].Value.ToString());
            myName      = Convert.ToString(rec.Fields["curName"].Value);


            if (!(calc == -1 && total == -1))
            {
                if (calc == -1 && total == 0)
                {
                    returnable = "Verifying data...";
                }
                if (calc > 0 && total > 0)
                {
                    returnable = "Calculating " + myName + " (" + calc + " of " + total + ")";
                    //report += "Calculating " + currentCalc + " out of " + totalCalc + " ...";
                }
            }
            else
            {
                returnable = "Verifying data...";
            }
        }
        catch (Exception)
        {
            returnable = "Error...";
        }
        finally
        {
            DbUse.CloseAdo(conn);
            DbUse.CloseAdoRec(rec);
        }



        return(returnable);
    }
Example #13
0
    public static bool isReCalcNecessary(string username, string path)
    {
        Boolean resultMessage;


        if (isCalculating(path))
        {
            resultMessage = false;
        }
        else
        {
            ClassF classE1_1 = new ClassF(path);
            classE1_1.Open();

            try
            {
                int totalCalc = 0;

                classE1_1.username = username;
                classE1_1.SetBasicModelInfo();
                classE1_1.calc_return = 0;     //0 - none, 1 labor, 2 eq over util, 4 warnings 8 errors
                ADODB.Recordset recNeedCalc = new ADODB.Recordset();
                //check if basecase needs recalc and add to totalCalc
                DbUse.open_ado_rec(classE1_1.globaldb, ref recNeedCalc, "SELECT * FROM zs0tblWhatIf WHERE zs0tblWhatIf.WID=0;");
                int basecaserecalc = Convert.ToInt32(recNeedCalc.Fields["recalc"].Value);
                if (basecaserecalc != 0)
                {
                    totalCalc++;
                }


                bool recOpened = DbUse.OpenAdoRec(classE1_1.globaldb, recNeedCalc, "SELECT * FROM tblWhatIf WHERE FamilyID = 0 AND recalc = true AND display = -1;");

                while (!recNeedCalc.EOF)
                {
                    totalCalc++;
                    recNeedCalc.MoveNext();
                }
                DbUse.CloseAdoRec(recNeedCalc);


                if (totalCalc > 0)
                {
                    resultMessage = true;
                }
                else
                {
                    resultMessage = false;
                }
            }
            catch (Exception)
            {
                resultMessage = false;
            }
            classE1_1.Close();
        }
        return(resultMessage);
    }
    //ORIGINAL
    //protected void RunLogin()
    //{
    //    string strUsername = Request.Form["txtUsername"];//should use Server.Htmlencode?
    //    strUsername = MyUtilities.clean(strUsername);
    //    string strPassword = Request.Form["txtPassword"];//should use Server.Htmlencode?

    //    //try
    //    //{
    //    //    loginCount = int.Parse(Request.Form["hidden1"]);
    //    //}
    //    //catch
    //    //{
    //    //    loginCount = 0;
    //    //}


    //    try
    //    {

    //        //if (loginCount > MAX_TRIES)
    //        //{

    //        //    throw new Exception("Too many Attempts!");

    //        //}


    //        if (!DbUse.CookiesEnabled())
    //        {
    //            throw new Exception(ERROR_COOKIES);
    //        }

    //        if (strUsername == "" | strPassword == "")
    //        {
    //            throw new Exception("Please Enter a Username or Password");
    //        }

    //        if (!IsValidCaptcha())
    //        {
    //            throw new Exception("Captcha Rejected!");
    //        }

    //        RecognizeUser(strUsername, strPassword);

    //        if (!IsUserLoggedIn(strUsername))
    //        {
    //            var mySession = HttpContext.Current.Session;
    //            string mySessionID = mySession.SessionID;
    //            int sessionID = mySession.LCID;
    //            //int sessionID = System.Diagnostics.Process.GetCurrentProcess().SessionId;
    //            string cookieid = MyUtilities.clean(DateTime.Now.ToString() + sessionID);
    //            cookieid = MyUtilities.clean(cookieid, ' '); // remove spaces
    //            cookieid = PasswordHash.PasswordHash.CreateHash(cookieid); //encode
    //            cookieid = MyUtilities.clean(cookieid);

    //            HttpCookie newcookie = new HttpCookie(DbUse.LOGIN_COOKIE)
    //            {
    //                Value = cookieid,
    //                //Expires = DateTime.Now.AddSeconds(10)
    //                Expires = DateTime.Now.AddMinutes(20)
    //            };

    //            Response.Cookies.Add(newcookie);

    //            SetCookieId(strUsername, cookieid, mySessionID, DateTime.Now.AddMinutes(20).Ticks);
    //            //Session["username"] = strUsername;


    //            try
    //            {
    //                string lastNewLoginTime = GetMysqlDatabaseField("newLogin", cookieid);
    //                WriteLoginTimesToDb(DateTime.Now, lastNewLoginTime, cookieid);
    //                DeleteGraphs(); // delete all the graphs from last session
    //            }
    //            catch (Exception excep)
    //            {
    //                logFiles.ErrorLog(excep);
    //            }


    //        }
    //        else
    //        {

    //            throw new Exception(ERROR_DUPLICATE_LOGIN);
    //            //HOW TO ASK USER IF WE CAN KICK THIS USER?
    //        }
    //        //Server.Transfer(REDIRECT_PAGE);
    //        //Server.Transfer(PAGENAME);
    //        Response.Redirect(PAGENAME, true);
    //    }
    //    catch (Exception ex)
    //    {

    //        //loginCount++;
    //        //hidden1.Value = loginCount + "";

    //        if (ex.Message.ToLower().IndexOf("object reference") == 0)
    //        {
    //            txtError += " " + ex.StackTrace;
    //        }
    //        else
    //        {
    //            txtError = ex.Message;
    //        }

    //    }
    //    lblError.Text = txtError;
    //    lblError.CssClass = "lblErrorVis";


    //}

    protected void RecognizeUser(string username, string psswd)
    {
        string sqlString = "SELECT id, usercode FROM userlog WHERE username = '******';";
        int    id        = -1;

        conn = new Connection();
        rec  = new Recordset();
        bool openedCon = DbUse.OpenAdoMysql(conn);
        bool openedRec = DbUse.OpenAdoRec(conn, rec, sqlString);

        try
        {  //An error has occured. Try logging in again.
            if (!openedCon || !openedRec)
            {
                throw new Exception("An error has occured. Try logging in again.");
            }
            else if (rec.EOF)
            {
                throw new Exception("Invalid username or password.");
            }
            else
            {
                string correctHash = rec.Fields["usercode"].Value.ToString();
                if (!PasswordHash.PasswordHash.ValidatePassword(psswd, correctHash))
                {
                    throw new Exception("Invalid username or password.");
                }
                else
                {
                    try
                    {
                        id = int.Parse(rec.Fields["id"].Value.ToString());
                    }
                    catch (Exception exp)
                    {
                        logFiles.ErrorLog(exp);
                    }
                }
            }
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
            if (id != -1)
            {
                // clean up previous calculation progress
                DbUse.RunMysql("DELETE usercalc.* FROM usercalc WHERE id = " + id);
            }
        }
        catch (Exception ex)
        {
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
            throw ex;
        }
    }
    public static bool CalculationsCancelled(string cookieid)
    {
        bool cancelled = false;

        ADODB.Connection connMySql = new ADODB.Connection();
        ADODB.Recordset  recMySql  = new ADODB.Recordset();
        DbUse.OpenAdoMysql(connMySql);
        DbUse.OpenAdoRec(connMySql, recMySql, "SELECT usercalc.cancel FROM usercalc INNER JOIN userlist ON userlist.id = usercalc.id WHERE userlist.sessionid =  '" + HttpContext.Current.Session.SessionID + "';");
        try
        {
            cancelled = !recMySql.Fields["cancel"].Value.ToString().Equals("0");
        }
        catch (Exception) { }
        DbUse.CloseAdoRec(recMySql);
        DbUse.CloseAdo(connMySql);
        return(cancelled);
    }
    public static bool ValidateSession()
    {
        bool   returnable    = false;
        bool   adoOpened     = DbUse.OpenAdoMysql(conn);
        string commandString = "SELECT * FROM userlist WHERE username = '******';";
        bool   adoRecOpened  = DbUse.OpenAdoRec(conn, rec, commandString);
        string dbSessionID   = rec.Fields["sessionid"].Value.ToString();

        DbUse.CloseAdo(conn);
        DbUse.CloseAdoRec(rec);

        if (!String.IsNullOrEmpty(dbSessionID) && GetSessionID().Equals(dbSessionID))
        {
            returnable = true;
        }
        return(returnable);
    }
Example #17
0
    } // end function;

    public string get_gen_t2()
    {
        ADODB.Recordset reccust = null;
        string          retval;

        //Set Database variable;
        DbUse.open_ado_rec(globaldb, ref reccust, "tblgeneral");

        reccust.MoveFirst();

        retval = Convert.ToString((float)reccust.Fields["rtu1c"].Value);


        DbUse.CloseAdoRec(reccust);
        reccust = null;
        return(retval); //exit  Function;
    } // end function;
    public static string GetErrorMessage(ClassE classE1_1)
    {
        ADODB.Recordset reccust = null;
        string          errorMsg;

        classE1_1.Open();
        DbUse.open_ado_rec(classE1_1.globaldb, ref reccust, "SELECT zstblErrors.* FROM zstblErrors ORDER BY zstblErrors.Level, zstblErrors.text,  zstblErrors.Table, "
                           + " zstblErrors.equipid, zstblErrors.partid; "); //  6-26-17  sort by ...

        errorMsg = "";
        while (!reccust.EOF)
        {
            errorMsg = errorMsg + (string)reccust.Fields["Text"].Value + "<br/>";
            reccust.MoveNext();
        }
        DbUse.CloseAdoRec(reccust);
        return(errorMsg);
    }
    }/// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public int unique_user_name(string groupname, string newname)
    {
        /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        int ret = 0;
        //  try
        //  {

        string entry;

        ADODB.Connection conn = new ADODB.Connection();
        ADODB.Recordset  rec  = new ADODB.Recordset();

        bool adoOpened = DbUse.OpenAdoMysql(conn);


        string commandString = "SELECT `webmpx`.Group_members.Username, `webmpx`.Group_members.Groupname FROM `webmpx`.Group_members WHERE (((`webmpx`.Group_members.Username)='" + newname + "') AND ((Group_members.Groupname)='" + groupname + "')) ;";

        bool adoRecOpened = DbUse.OpenAdoRec(conn, rec, commandString);

        if (!adoOpened || !adoRecOpened)
        {
            throw new Exception("Error in opening database/dataset.");
        }
        ret = -1;      //  unique name ok

        try {
            entry = rec.Fields["Username"].Value.ToString();
            ret   = 0;    //  not unique  name is there...
        } catch (Exception) {
            //  is unique and ret is set
            ret = -1;
        }     //  end try catch
        DbUse.CloseAdo(conn);
        DbUse.CloseAdoRec(rec);
        return(ret);

        /*       } catch (Exception ex) {
         *         if (ex.Message.IndexOf("not found") >= 0) {
         *             return 0;
         *         }
         *     }  //  end try-catch
         * */
        // return 0;
    }  //  end routine
Example #20
0
    public bool CheckCurrPassword(string cookieid, string psswd)
    {
        bool   correct   = false;
        string sqlString = "SELECT userlog.id, userlog.usercode, userlist.userid FROM userlog INNER JOIN userlist ON userlog.id = userlist.id WHERE userlist.sessionid = '" + cookieid + "';";

        conn = new ADODB.Connection();
        rec  = new ADODB.Recordset();
        bool openedCon = DbUse.OpenAdoMysql(conn);
        bool openedRec = DbUse.OpenAdoRec(conn, rec, sqlString);

        try {
            if (!openedCon || !openedRec)
            {
                throw new Exception("An error has occured. Please try again.");
            }
            else if (rec.EOF)
            {
                DbUse.CloseAdoRec(rec);
                DbUse.CloseAdo(conn);
                Response.Redirect(LOGOUT_PAGE, true);
            }
            else
            {
                string correctHash = rec.Fields["usercode"].Value.ToString();
                if (!PasswordHash.PasswordHash.ValidatePassword(psswd, correctHash))
                {
                    throw new Exception("Current password is incorrect.");
                }
                else
                {
                    correct = true;
                }
            }
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
            Master.ShowErrorMessage(ex.Message);
        } finally {
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
        }

        return(correct);
    }
Example #21
0
    public bool ChangePassword(string cookieid, string pswdNew)
    {
        bool   updated   = false;
        string sqlString = "SELECT id FROM userlist WHERE sessionid = '" + cookieid + "';";
        int    id        = -1;

        conn = new ADODB.Connection();
        rec  = new ADODB.Recordset();
        bool openedCon = DbUse.OpenAdoMysql(conn);
        bool openedRec = DbUse.OpenAdoRec(conn, rec, sqlString);

        try {
            if (!openedCon || !openedRec)
            {
                throw new Exception("An error has occured. Please try again.");
            }
            else if (rec.EOF)
            {
                throw new Exception("An internal error has occured. Missing data.");
            }
            else
            {
                id = int.Parse(rec.Fields["id"].Value.ToString());
            }
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
            Master.ShowErrorMessage(ex.Message);
            return(false);
        } finally {
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
        }
        string hash = PasswordHash.PasswordHash.CreateHash(pswdNew);

        updated = DbUse.RunMysql("UPDATE userlog SET usercode = '" + hash + "' WHERE id = " + id + ";");
        if (!updated)
        {
            Master.ShowErrorMessage("Password was not changed. Please try again.");
        }

        return(updated);
    }
    public static bool DuplicateOperNamesOrNumbers(string connectionString, int prodId)
    {
        bool duplicate = false;

        ADODB.Connection conn     = new ADODB.Connection();
        ADODB.Recordset  rec      = new ADODB.Recordset();
        string           sqlQuery = "SELECT tblOper_1.ProdFore, tblOper.OpNum, tblOper.OpNam FROM tblOper INNER JOIN tblOper AS tblOper_1 ON (tblOper.OpNam = tblOper_1.OpNam) AND (tblOper.ProdFore = tblOper_1.ProdFore) WHERE ((tblOper.OpNum)<[tbloper_1].[opnum])";

        if (prodId > 0)
        {
            sqlQuery += " AND tblOper_1.ProdFore = " + prodId;
        }
        sqlQuery += ";";
        DbUse.OpenAdo(conn, connectionString);
        DbUse.OpenAdoRec(conn, rec, sqlQuery);
        try {
            duplicate = !rec.EOF;
        } catch (Exception exp) {
            LogFiles logFiles = new LogFiles();
            logFiles.ErrorLog(exp);
        } finally {
            DbUse.CloseAdoRec(rec);
        }

        sqlQuery = "SELECT tblOper_1.ProdFore, tblOper.OpNum, tblOper.OpNam FROM tblOper INNER JOIN tblOper AS tblOper_1 ON (tblOper.OpNum = tblOper_1.OpNum) AND (tblOper.ProdFore = tblOper_1.ProdFore) WHERE StrComp(tblOper.OpNam, tbloper_1.OpNam) = 1";
        if (prodId > 0)
        {
            sqlQuery += " AND tblOper_1.ProdFore = " + prodId;
        }
        sqlQuery += ";";
        DbUse.OpenAdoRec(conn, rec, sqlQuery);
        try {
            duplicate = duplicate || !rec.EOF;
        } catch (Exception exp) {
            LogFiles logFiles = new LogFiles();
            logFiles.ErrorLog(exp);
        } finally {
            DbUse.CloseAdoRec(rec);
        }
        DbUse.CloseAdo(conn);
        return(duplicate);
    }
Example #23
0
    } // end function;

    int get_gen_id()
    {
        //on error GoTo err_genid;

        ADODB.Recordset reccust = null;
        int             retval;

        //Set Database variable;
        DbUse.open_ado_rec(globaldb, ref reccust, "tblgeneral");

        reccust.MoveFirst();

        retval = (int)reccust.Fields["generalid"].Value;

        //exit_genid:
        DbUse.CloseAdoRec(reccust);
        reccust = null;
        return(retval); //exit  Function;
        //err_genid:
        // msgbox(ErrorToString(), 0, appl_name);
        // resume  exit_genid;
    } // end function;
Example #24
0
    } // end sub;

    public string get_op_time_unit()
    {
        //on error GoTo err_op_name;

        ADODB.Recordset reccust = null;
        string          retval;

        //Set Database variable;
        DbUse.open_ado_rec(globaldb, ref reccust, "tblgeneral");

        reccust.MoveFirst();

        retval = (string)reccust.Fields["TUProd"].Value;

        //exit_op_name:
        DbUse.CloseAdoRec(reccust);
        reccust = null;
        return(retval); //exit  Function;
        //err_op_name:
        // msgbox(ErrorToString(), 0, appl_name);
        // resume  exit_op_name;
    } // end function;
Example #25
0
    } // end function;

    public string get_utlimit()
    {
        //on error GoTo err_utlimit;

        ADODB.Recordset reccust = null;
        string          retval;

        //Set Database variable;
        DbUse.open_ado_rec(globaldb, ref reccust, "tblgeneral");

        reccust.MoveFirst();

        retval = Convert.ToString((float)reccust.Fields["utlimit"].Value);

        //exit_utlimit:
        DbUse.CloseAdoRec(reccust);
        reccust = null;
        return(retval); //exit  Function;
        //err_utlimit:
        // msgbox(ErrorToString(), 0, appl_name);
        // resume  exit_utlimit;
    } // end function;
    public static bool SameOperNameNumExists(string opName, int prodId, int opNum, int opId, string connectionString, LogFiles logFiles)
    {
        bool exists = false;

        ADODB.Connection conn = new ADODB.Connection();
        ADODB.Recordset  rec  = new ADODB.Recordset();

        opName = opName.ToUpper();

        bool   adoOpen     = DbUse.OpenAdo(conn, connectionString);
        string queryString = "SELECT OpID, OpNam, OpNum, Prodfore FROM tblOper WHERE Prodfore = " + prodId + " AND OpNam = '" + opName + "' AND OpNum = " + opNum + " AND OpID <> " + opId;
        bool   recOpen     = DbUse.OpenAdoRec(conn, rec, queryString);

        try {
            if (adoOpen && recOpen)
            {
                if (opId != -1)
                {
                    // we actually know  the opid of the record
                    exists = !rec.EOF;
                }
                else
                {
                    // don't know opid - one record it is the one we previously entered, more records - more opers with same name and num
                    if (!rec.EOF)
                    {
                        rec.MoveNext();
                        exists = !rec.EOF;
                    }
                }
            }
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
        } finally {
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
        }
        return(exists);
    }
Example #27
0
    double get_opt_value()
    {
        double retval;
        string str1;

        ADODB.Recordset recprod = null;

        retval = 0;
        //classE1_1.Open();
        str1 = "SELECT Sum(([Value]*[WIP])) AS Expr1, tblRsProd.WID FROM tblRsProd INNER JOIN tblProdFore ON tblRsProd.ProdID = tblProdFore.ProdID GROUP BY tblRsProd.WID HAVING (((tblRsProd.WID)=" + classE1_1.glngwid + "));";
        DbUse.open_ado_rec(classE1_1.globaldb, ref recprod, str1);
        if (recprod != null)
        {
            if (recprod.EOF == false)
            {
                retval = (double)recprod.Fields["Expr1"].Value;
            }
        }
        DbUse.CloseAdoRec(recprod);
        //classE1_1.Close();
        return(retval);
    }
Example #28
0
    } // end sub;

    void set_utlimit(float x1)
    {
        //on error GoTo err_setlimit;

        ADODB.Recordset reccust = null;

        //Set Database variable;
        DbUse.open_ado_rec(globaldb, ref reccust, "tblgeneral");

        reccust.MoveFirst();
        //'reccust.edit;
        reccust.Fields["utlimit"].Value = x1;
        reccust.Update();


        //exit_setlimit:
        DbUse.CloseAdoRec(reccust);
        reccust = null;
        return; //exit  Sub;
        //err_setlimit:
        // msgbox(ErrorToString(), 0, appl_name);
        //RESUME NEXT
    } // end sub;
    public int GetPasswordResetLinkId(string link)
    {
        string sqlString = "SELECT id, tempHash, mail, expiry FROM usercred WHERE tempHash = '" + link + "';";
        int    id        = -1;

        ADODB.Connection conn      = new ADODB.Connection();
        ADODB.Recordset  rec       = new ADODB.Recordset();
        bool             openedCon = DbUse.OpenAdoMysql(conn);
        bool             openedRec = DbUse.OpenAdoRec(conn, rec, sqlString);

        try {
            if (!openedCon || !openedRec)
            {
                throw new Exception("Error in opening database/dataset.");
            }
            else if (rec.EOF)
            {
                throw new Exception("Password reset link does not exist.");
            }
            else
            {
                long linkTicks = long.Parse(rec.Fields["expiry"].Value.ToString());
                if (!IsLinkValid(linkTicks))
                {
                    throw new Exception("Password reset link has expired.");
                }
                id = int.Parse(rec.Fields["id"].Value.ToString());
            }
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
        } finally {
            DbUse.CloseAdoRec(rec);
            DbUse.CloseAdo(conn);
        }

        return(id);
    }
Example #30
0
    } // end sub;

    void set_modified_date()
    {
        //on error GoTo err_setdate;

        ADODB.Recordset reccust = null;

        //Set Database variable;
        DbUse.open_ado_rec(globaldb, ref reccust, "tblgeneral");

        reccust.MoveFirst();
        //'reccust.edit;
        reccust.Fields["DateM"].Value = System.DateTime.Now;
        reccust.Update();



        //exit_setdate:
        DbUse.CloseAdoRec(reccust);
        reccust = null;
        return; //exit  Sub;
        //err_setdate:
        // msgbox(ErrorToString(), 0, appl_name);
        //RESUME NEXT
    } // end sub;