Esempio n. 1
0
        public static bool CreateUploadRecord(User user, DateTime reqDate, string reqType, string fileName)
        {
            // uniquekey, preqdate, customer, partner, preqtype, preqaction, pfilename, pcustomfile, presultfile, presultdate, processed
            DBConnect connection = new DBConnect();
            bool      success    = false;

            try
            {
                connection.Connect(ConnectionsMgr.GetOCConnInfo(user, _Database.Home));
                var insertVals = new Dictionary <string, string>()
                {
                    { _Column.UniqueKey, connection.GetNewKey() },
                    { _Column.PReqDate, reqDate.ToString("yyyy-MM-dd HH:mm:ss") },
                    { _Column.Customer, user.Customer.SQLEscape() },
                    { _Column.PReqType, reqType.SQLEscape() },
                    { _Column.PFileName, fileName.SQLEscape() },
                    { _Column.PCustomFile, "1" },
                    { _Column.Partner, user.ActivePartner.SQLEscape() }
                };
                using (var res = connection.Insert(_Table.ProcessQ, insertVals.ToNameValueCollection()))
                {
                    success = res.AffectedRows != 0;
                }
                connection.Close();
                return(success);
            }
            catch (Exception e)
            {
                ProgramLog.LogError(user, "ProcessQueue", "CreateUploadRecord", e.Message);
                return(false);
            }
        }
Esempio n. 2
0
        public static List <ProcessRecord> GetPreviousRecords(User user)
        {
            List <ProcessRecord> listRecord = new List <ProcessRecord>();
            DBConnect            connection = new DBConnect();

            try
            {
                var filter = string.Format("WHERE {0}='{1}' AND {2}='{3}' AND {4}>'{5}'", _Column.Customer, user.Customer.SQLEscape(), _Column.Partner, user.ActivePartner.SQLEscape(), _Column.PReqDate, DateTime.Now.Subtract(new TimeSpan(30, 0, 0, 0)).ToString("yyyy-MM-dd HH:mm:ss"));
                connection.Connect(ConnectionsMgr.GetOCConnInfo(user, _Database.Home));
                using (var query = connection.Select(new[] { _Column.PReqDate, _Column.PReqType, _Column.Processed }, _Table.ProcessQ, filter))
                {
                    while (query.Read())
                    {
                        ProcessRecord pr = new ProcessRecord();
                        pr.Date   = query.Field(0, "");
                        pr.Type   = query.Field(1, "");
                        pr.Status = query.Field(2, "");
                        listRecord.Add(pr);
                    }
                }
                connection.Close();
                return(listRecord);
            }
            catch (Exception e)
            {
                ProgramLog.LogError(user, "ProcessQueue", "GetPreviousRecords", e.Message);
                connection.Close();
                return(new List <ProcessRecord>());
            }
        }
Esempio n. 3
0
        public static Dictionary <string, string> GetAllowedApps(User user)
        {
            DBConnect connection = new DBConnect();

            try
            {
                connection.Connect(ConnectionsMgr.GetOCConnInfo(user, _Database.Home));
                Dictionary <string, string> ret = new Dictionary <string, string>();

                using (var queryUserLevelAP = connection.Select(appFlags, _Table.UserInfo, string.Format("WHERE {0}='{1}' AND {2}='{3}' AND {4}='{5}'", _Column.Customer, user.Customer.SQLEscape(), _Column.Partner, user.ActivePartner.SQLEscape(), _Column.UserName, user.UserName.SQLEscape())))
                {
                    while (queryUserLevelAP.Read())
                    {
                        for (int i = 0; i < appFlags.Length; i++)
                        {
                            string f = queryUserLevelAP.Field(i);
                            if (f == "1")
                            {
                                string name = columnToDetail[appFlags[i]].appName;
                                string url  = columnToDetail[appFlags[i]].appURL;
                                if (!ret.ContainsKey(name))
                                {
                                    ret.Add(name, url);
                                }
                            }
                        }
                    }
                    if (ret.Count > 0)
                    {
                        return(ret);
                    }
                }

                using (var queryCustPartAP = connection.Select(appFlags, _Table.NetGroup, string.Format("WHERE {0}='{1}' AND {2}='{3}'", _Column.Customer, user.Customer.SQLEscape(), _Column.Partner, user.ActivePartner.SQLEscape())))
                {
                    while (queryCustPartAP.Read())
                    {
                        for (int i = 0; i < appFlags.Length; i++)
                        {
                            string f = queryCustPartAP.Field(i);
                            if (f == "1")
                            {
                                string name = columnToDetail[appFlags[i]].appName;
                                string url  = columnToDetail[appFlags[i]].appURL;
                                if (!ret.ContainsKey(name))
                                {
                                    ret.Add(name, url);
                                }
                            }
                        }
                    }
                    return(ret);
                }
            }
            catch (Exception e)
            {
                ProgramLog.LogError(user, nameof(AppManagement), nameof(GetAllowedApps), e.Message);
                return(new Dictionary <string, string>());
            }
        }
Esempio n. 4
0
        protected void SetDevelopmentInfo(User user)
        {
            DatabaseInfo  di      = null;
            string        sFormat = "{1} ({0})";
            List <string> conns   = new List <string>();

            di = ConnectionsMgr.GetOCConnInfo(user);
            conns.Add(string.Format(sFormat, di.Port, di.Id));
            di = ConnectionsMgr.GetNPConnInfo(user);
            conns.Add(string.Format(sFormat, di.Port, di.Id));
            di = ConnectionsMgr.GetSHConnInfo(user);
            conns.Add(string.Format(sFormat, di.Port, di.Id));
            di = ConnectionsMgr.GetSLConnInfo(user);
            conns.Add(string.Format(sFormat, di.Port, di.Id));

            lblDeNotice.Text    = string.Format("Development Environment: {0}", string.Join(", ", conns));
            divDeNotice.Visible = true;
        }
Esempio n. 5
0
        public static bool BeginGuestSession()
        {
            try
            {
                // Check existence of session
                HttpSessionState session = HttpContext.Current.Session;
                HttpRequest      request = HttpContext.Current.Request;
                if (session == null)
                {
                    return(false);
                }

                User user = new User();
                user.UserName    = "******";
                user.Email       = "*****@*****.**";
                user.FirstName   = "Guest";
                user.LastName    = "";
                user.Level       = 1;
                user.Customer    = "GST1";
                user.PartnerList = new List <PartnerDetail>();
                user.IsGuest     = true;
                List <string> partnerList = new List <string>()
                {
                    "PART"
                };
                bool isTest = false;
                //CHECK DEVELOPMENT/TEST ENVIRONMENT
                string hostname = request.Url.Authority;
                if (hostname == "10.0.0.245:30658")
                {
                    isTest = true;
                }
#if DEBUG
                isTest = true;
#endif

                // Set connection IDs
                if (!ConnectionsMgr.SetConnIDs(user, isTest))
                {
                    // No Conn IDs?
                    ProgramLog.LogError(user, "SessionHandler", "GetUserInfo", string.Format("Unable to get connection IDs for customer {0} and partner {1}.", user.Customer, user.ActivePartner));
                    return(false);
                }
                DBConnect connection = new DBConnect();
                // Set partner info
                connection.Connect(ConnectionsMgr.GetAdminConnInfo());
                using (var res = connection.Select(new[] { columnPartner, columnPartnerName }, tablePartnerInfo, string.Format("WHERE {0} IN ({1})", columnPartner, string.Join(",", partnerList.Select(p => "'" + p + "'")))))
                {
                    while (res.Read())
                    {
                        user.PartnerList.Add(new PartnerDetail()
                        {
                            ID = res.Field(0), FullName = res.Field(1)
                        });
                    }
                }
                user.PartnerIndex = 0;
                connection.Close();
                // Set extra company info.
                connection.Connect(ConnectionsMgr.GetOCConnInfo(user));
                using (var res = connection.Select(columnCompanyName, tableCustomerInfo, string.Format("WHERE {0}='{1}'", columnCustomer, user.Customer)))
                {
                    if (res.AffectedRows == 0)
                    {
                        // No company name?
                        ProgramLog.LogError(user, "SessionHandler", "GetUserInfo", string.Format("Unable to find company name in {0} for customer {1}", tableCustomerInfo, user.Customer));
                        connection.Close();
                        return(false);
                    }
                    res.Read();
                    user.CompanyName = res.Field(0);
                }
                connection.Close();

                session[SKeys.User]        = user;
                session[SKeys.IsTest]      = isTest;
                session[SKeys.LandingPg]   = "Default.aspx";
                session[SKeys.TokenSet]    = new HashSet <string>();
                session[SKeys.TrxDict]     = ProcessQueue.GetReqTypeDict(user);
                session[SKeys.IsOCSession] = false;
                return(true);
            }
            catch (Exception e)
            {
                ProgramLog.LogError("Guest", "EDIO", "EDIO", "SessionHandler", "BeginGuestSession", e.Message);
                return(false);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Fetches user information based on the username.
        /// </summary>
        /// <param name="user">The user object.</param>
        /// <param name="usUserName">The username of the user.</param>
        /// <returns>True if successful, false otherwise.</returns>
        private static bool GetUserInfo(User user, string usUserName, bool isTest)
        {
            string               sUserName         = usUserName.SQLEscape();
            List <string>        partnerList       = new List <string>();
            List <PartnerDetail> partnerDetailList = new List <PartnerDetail>();
            DBConnect            connection        = new DBConnect();

            try
            {
                connection.Connect(ConnectionsMgr.GetAuthConnInfo());
                using (var res = connection.Select(new[] { columnEmail, columnFirstName, columnLastName, columnLevel, columnOrgID, columnPartnerList }, tableUserInfo, string.Format("WHERE {0}='{1}'", columnUserName, sUserName)))
                {
                    if (!res.Read())
                    {
                        connection.Close();
                        return(false);
                    }
                    user.UserName  = sUserName;
                    user.Email     = res.Field(0);
                    user.FirstName = res.Field(1);
                    user.LastName  = res.Field(2);
                    user.Level     = (int)double.Parse(res.Field(3));
                    user.Customer  = res.Field(4).ToUpper();
                    partnerList.AddRange(res.Field(5).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(pt => pt.Trim()));
                }
                connection.Close();

                // Set partner info
                connection.Connect(ConnectionsMgr.GetAdminConnInfo());
                using (var res = connection.Select(new[] { columnPartner, columnPartnerName }, tablePartnerInfo, string.Format("WHERE {0} IN ({1})", columnPartner, string.Join(",", partnerList.Select(p => "'" + p + "'")))))
                {
                    while (res.Read())
                    {
                        partnerDetailList.Add(new PartnerDetail()
                        {
                            ID = res.Field(0), FullName = res.Field(1)
                        });
                    }
                }
                connection.Close();

                if (partnerDetailList.Count == 0)
                {
                    // No partners?
                    ProgramLog.LogError(user.UserName, user.Customer, "EDIO", "SessionHandler", "GetUserInfo", string.Format("Unable to find partner list in {0} for user {1}.", tablePartnerInfo, user.UserName));
                    return(false);
                }
                user.PartnerList  = partnerDetailList;
                user.PartnerIndex = 0;

                // Set connection IDs
                if (!ConnectionsMgr.SetConnIDs(user, isTest))
                {
                    // No Conn IDs?
                    ProgramLog.LogError(user, "SessionHandler", "GetUserInfo", string.Format("Unable to get connection IDs for customer {0} and partner {1}.", user.Customer, user.ActivePartner));
                    return(false);
                }

                // Set extra company info.
                connection.Connect(ConnectionsMgr.GetOCConnInfo(user));
                using (var res = connection.Select(columnCompanyName, tableCustomerInfo, string.Format("WHERE {0}='{1}'", columnCustomer, user.Customer)))
                {
                    if (res.AffectedRows == 0)
                    {
                        // No company name?
                        ProgramLog.LogError(user, "SessionHandler", "GetUserInfo", string.Format("Unable to find company name in {0} for customer {1}", tableCustomerInfo, user.Customer));
                        connection.Close();
                        return(false);
                    }
                    res.Read();
                    user.CompanyName = res.Field(0);
                }
                connection.Close();

                return(true);
            }
            catch (Exception e)
            {
                ProgramLog.LogError("", "EDIO", "EDIO", "SessionHandler", "GetUserInfo", e.Message);
                return(false);
            }
        }