Ejemplo n.º 1
0
        public bool Register() // UserTable Methods
        {
            try
            {
                User newuser = new User();
                newuser.Username    = HttpContext.Current.Session["r_username"].ToString();
                newuser.Firstname   = HttpContext.Current.Session["r_firstname"].ToString();
                newuser.Lastname    = HttpContext.Current.Session["r_lastname"].ToString();
                newuser.Gender      = HttpContext.Current.Session["r_gender"].ToString();
                newuser.Email       = HttpContext.Current.Session["r_email"].ToString();
                newuser.Phonenumber = HttpContext.Current.Session["r_pnumber"].ToString();
                newuser.Password    = HttpContext.Current.Session["r_password"].ToString();
                newuser.address     = HttpContext.Current.Session["r_address"].ToString();
                newuser.Usertype    = HttpContext.Current.Session["r_usertype"].ToString();
                UserTable.Add(newuser);
                SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void AddPlanningJournalEntry(AccountAction accountAction, int newCode)
        {
            UserTable myUDT = SapDiConnection.Instance.UserTables.Item("BMSINSPSCH");

            myUDT.Code = newCode.ToString();
            myUDT.Name = newCode.ToString();
            myUDT.UserFields.Fields.Item("U_OPPNUM").Value    = EditText0.Value;
            myUDT.UserFields.Fields.Item("U_RUNDATE").Value   = accountAction.RunDate;
            myUDT.UserFields.Fields.Item("U_AMOUNT").Value    = accountAction.Amount;
            myUDT.UserFields.Fields.Item("U_DEBITACC").Value  = ((int)accountAction.FromAccount).ToString();
            myUDT.UserFields.Fields.Item("U_CREDITACC").Value = ((int)accountAction.ToAccount).ToString();
            myUDT.UserFields.Fields.Item("U_CURRENCy").Value  = accountAction.Currency;

            myUDT.Add();
        }
Ejemplo n.º 3
0
        ///// <summary>
        ///// Key: UserId + '_' + Symbol, Value: List of the closed position. Yiyang: Change to documents instead of Queue
        ///// </summary>
        //public Dictionary<string, List<ClosePosition>> ClosedPositionTable
        //{
        //    get;
        //    set;
        //}

        ///// <summary>
        ///// Key: UserId + '_' + Symbol, Value: List of the open position. Yiyang: Change to documents instead of Queue
        ///// </summary>
        //public Dictionary<string, List<OpenPosition>> OpenPositionTable
        //{
        //    get;
        //    set;
        //}

        /// <summary>
        /// Add a valid (verified) user
        /// </summary>
        /// <param name="user"></param>
        public enumStatus AddUser(User user)
        {
            string jsonDoc = user.ToString();

            try
            {
                Users.Add(user.Id, jsonDoc);
                UserTable.Add(user.UserName, user);
                Positions.Add(user.Id, new List <Position>());
                return(enumStatus.UserAdded);
            }
            catch (Exception ex)
            {
                ServerLog.LogException(ex, string.Format("Add User: {0}", user.ToString()));
                return(enumStatus.UserAddFailed);
            }
            //lock (syncRoot)
            //{

            //}
        }
Ejemplo n.º 4
0
 private void BuildTable(IEnumerable <User> users)
 {
     foreach (var user in users)
     {
         UserTable.Add(
             new User
         {
             Id          = user.Id,
             Username    = user.Username,
             FirstName   = user.FirstName,
             LastName    = user.LastName,
             Email       = user.Email,
             PhoneNumber = user.PhoneNumber,
             Address     = user.Address,
             DateOfBirth = user.DateOfBirth,
             AnnualWage  = user.AnnualWage,
             Role        = user.Role,
             RoleId      = user.RoleId,
             UserRoleId  = user.UserRoleId,
         });
     }
 }
Ejemplo n.º 5
0
        public string SetUser()
        {
            var first = new User
            {
                Age         = 12,
                Description = "Test User",
                Email       = "*****@*****.**",
                Interests   = new[] { true, true, false, true },
                Name        = "John",
                SurName     = "Dow",
                UserStats   = new UserStats
                {
                    GoodMood       = 2,
                    NonPunctuality = 3,
                    SelfCentered   = 9
                }
            };


            UserTable.Add(first);

            return("OK");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Salva o log em banco de dados. Caso ocorra falha, o log será gerado no diretório raiz, dentro do diretório LogSystem
        /// </summary>
        /// <param name="text">A mensagem da exceção</param>
        /// <param name="type">O tipo de exceção</param>
        private void printText(string text, LogType type)
        {
            DateTime   dt            = DateTime.Now;
            LoggerData LoggerDataObj = null;
            string     Time          = String.Format("{0:HH:mm:ss}", dt);

            try
            {
                LoggerDataObj = new LoggerData();
                string form = "";
                if (DBFacade.getInstance().Connection.App.Forms.ActiveForm != null)
                {
                    try
                    {
                        form = DBFacade.getInstance().Connection.App.Forms.ActiveForm.TypeEx;
                    }
                    catch (Exception e)
                    {
                        form = "";
                    }
                }


                UserTable table = DBFacade.getInstance().getUserTable("SB1_ADDON_LOG");
                table.Code = "" + (dt.Ticks + 1);
                table.Name = "" + (dt.Ticks + 1);

                //Ajusta valores nos campos pois pode ocorrer exception caso esteja NULL
                addonVersion   = addonVersion == null ? "" : addonVersion;
                addonName      = addonName == null ? "" : addonName;
                companyVersion = companyVersion == null ? "" : companyVersion;
                libVersion     = libVersion == null ? "" : libVersion;
                type           = type == null ? LogType.INFO : type;
                text           = text == null ? "" : text;

                table.UserFields.Fields.Item("U_AddonVersion").Value   = addonVersion;
                table.UserFields.Fields.Item("U_AddonName").Value      = addonName;
                table.UserFields.Fields.Item("U_CompanyVersion").Value = companyVersion;
                table.UserFields.Fields.Item("U_Date").Value           = dt;
                table.UserFields.Fields.Item("U_LibVersion").Value     = libVersion;
                table.UserFields.Fields.Item("U_LogType").Value        = type.ToString();
                table.UserFields.Fields.Item("U_Text").Value           = text;
                table.UserFields.Fields.Item("U_Time").Value           = Time;
                table.UserFields.Fields.Item("U_User").Value           = user;
                table.UserFields.Fields.Item("U_FormID").Value         = form;
                table.UserFields.Fields.Item("U_XMLException").Value   = "";
                table.UserFields.Fields.Item("U_Operation").Value      = (opStack.Count == 0 ? "" : opStack.Peek());

                table.Add();
                table = null;

                LoggerDataObj.U_AddonVersion   = addonVersion;
                LoggerDataObj.U_CompanyVersion = companyVersion;
                LoggerDataObj.U_Date           = dt;
                LoggerDataObj.U_LibVersion     = libVersion;
                LoggerDataObj.U_LogType        = type.ToString();
                LoggerDataObj.U_Text           = text;
                LoggerDataObj.U_Time           = Time;
                LoggerDataObj.U_User           = user;
            }
            catch (Exception e)
            {
                LogManager.SaveLoggerData(LoggerDataObj);
                SB1ControlException.SB1ControlException.Save(e);
                //B1Connection.getInstance().App.SetStatusBarMessage("Erro ao escrever Log: " + e.Message, SAPbouiCOM.BoMessageTime.bmt_Long);
            }
        }
Ejemplo n.º 7
0
        public void Save(T model, bool retry = false)
        {
            Type type = typeof(T);

            var props = type.GetProperties().Where(r => r.Name != "Changed" && r.Name != "Code");

            UserTable userTable = (UserTable)Controller.ConnectionController.Instance.Company.UserTables.Item(TableName);

            try
            {
                if (userTable.GetByKey(model.Code.ToString()))
                {
                    foreach (var prop in props)
                    {
                        Model.BaseModel.NonDB nonDB = prop.GetCustomAttribute(typeof(Model.BaseModel.NonDB)) as Model.BaseModel.NonDB;

                        if (nonDB == null)
                        {
                            if (prop.PropertyType == typeof(Boolean))
                            {
                                userTable.UserFields.Fields.Item("U_" + prop.Name).Value = (bool)prop.GetValue(model) ? "Y" : "N";
                            }
                            else if (prop.PropertyType.IsEnum)
                            {
                                userTable.UserFields.Fields.Item("U_" + prop.Name).Value = (int)prop.GetValue(model);
                            }
                            else
                            {
                                userTable.UserFields.Fields.Item("U_" + prop.Name).Value = prop.GetValue(model);
                            }
                        }
                    }

                    userTable.Update();

                    Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();
                }
                else
                {
                    foreach (var prop in props)
                    {
                        Model.BaseModel.NonDB nonDB = prop.GetCustomAttribute(typeof(Model.BaseModel.NonDB)) as Model.BaseModel.NonDB;

                        if (nonDB == null)
                        {
                            if (prop.PropertyType == typeof(Boolean))
                            {
                                userTable.UserFields.Fields.Item("U_" + prop.Name).Value = (bool)prop.GetValue(model) ? "Y" : "N";
                            }
                            else if (prop.PropertyType.IsEnum)
                            {
                                userTable.UserFields.Fields.Item("U_" + prop.Name).Value = (int)prop.GetValue(model);
                            }
                            else
                            {
                                userTable.UserFields.Fields.Item("U_" + prop.Name).Value = prop.GetValue(model);
                            }
                        }
                    }

                    if (model.Code == 0)
                    {
                        Type seqDAOType = Type.GetType(type.AssemblyQualifiedName.Replace("Model", "DAO").Replace(type.Name.Replace("Model", "DAO"), "ConfigSeqDAO"));

                        if (seqDAOType == null)
                        {
                            model.Code = Controller.ConnectionController.Instance.ExecuteSqlForObject <int>("GetLastCode", TableName, new ConfigSeqDAO().TableName);
                        }
                        else
                        {
                            var dao = (DAO.ConfigSeqDAO)Activator.CreateInstance(seqDAOType);

                            model.Code = Controller.ConnectionController.Instance.ExecuteSqlForObject <int>("GetLastCode", TableName, dao.TableName);
                        }
                    }

                    userTable.UserFields.Fields.Item("U_Code").Value = model.Code;
                    userTable.Code = model.Code.ToString();
                    userTable.Name = model.Code.ToString();

                    userTable.Add();

                    try
                    {
                        Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();
                    }
                    catch
                    {
                        if (retry)
                        {
                            userTable.Add();

                            Type seqDAOType = Type.GetType(type.AssemblyQualifiedName.Replace("Model", "DAO").Replace(type.Name.Replace("Model", "DAO"), "ConfigSeqDAO"));

                            if (seqDAOType == null)
                            {
                                model.Code = Controller.ConnectionController.Instance.ExecuteSqlForObject <int>("GetLastCode", TableName, new ConfigSeqDAO().TableName);
                            }
                            else
                            {
                                var dao = (DAO.ConfigSeqDAO)Activator.CreateInstance(seqDAOType);

                                model.Code = Controller.ConnectionController.Instance.ExecuteSqlForObject <int>("GetLastCode", TableName, dao.TableName);
                            }

                            Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();
                        }
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(userTable);
                GC.Collect();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Salva o model no BD de acordo com o tipo da operação
        /// </summary>
        /// <param name="enumCrudOperation">Operação - Create ou Update</param>
        /// <param name="tableName">Nome da tabela</param>
        /// <param name="model">Modelo</param>
        private void SaveNonObjectModel(EnumCrudOperation enumCrudOperation)
        {
            UserTable utbUser       = SBOApp.Company.UserTables.Item(TableName.Replace("@", ""));
            string    code          = Model.GetType().GetProperty("Code").GetValue(Model, null).ToString();
            bool      alreadyExists = utbUser.GetByKey(code);

            if (!String.IsNullOrEmpty(code))
            {
                utbUser.Code = code;
            }
            else
            {
                utbUser.Code = CrudController.GetNextCode(TableName);
            }

            utbUser.Name = utbUser.Code;

            ModelControllerAttribute modelController;

            // Percorre as propriedades do Model
            foreach (PropertyInfo property in Model.GetType().GetProperties())
            {
                if (property.Name == "Code" || property.Name == "Name")
                {
                    continue;
                }

                // Busca os Custom Attributes
                foreach (Attribute attribute in property.GetCustomAttributes(true))
                {
                    modelController = attribute as ModelControllerAttribute;

                    if (modelController != null)
                    {
                        // Se não for DataBaseField não seta nas properties
                        if (!modelController.DataBaseFieldYN)
                        {
                            break;
                        }
                        if (String.IsNullOrEmpty(modelController.ColumnName))
                        {
                            modelController.ColumnName = property.Name;
                        }
                        utbUser.UserFields.Fields.Item(modelController.ColumnName).Value = property.GetValue(Model, null);
                    }
                    break;
                }
            }
            switch (enumCrudOperation)
            {
            case EnumCrudOperation.Create:
                utbUser.Add();
                break;

            case EnumCrudOperation.Update:
                utbUser.Update();
                break;

            default:
                break;
            }

            Marshal.ReleaseComObject(utbUser);
            utbUser = null;
            GC.Collect();
        }
 public string NewUser([FromBody] User user)
 {
     UserTable.Add(user);
     return(user.Email);
 }
Ejemplo n.º 10
0
 public virtual long add()
 {
     userTable.Code = code;
     userTable.Name = name;
     return(userTable.Add());
 }