Beispiel #1
0
 partial void Deletetbl_Inventory(tbl_Inventory instance);
Beispiel #2
0
 partial void Updatetbl_Inventory(tbl_Inventory instance);
Beispiel #3
0
 partial void Inserttbl_Inventory(tbl_Inventory instance);
Beispiel #4
0
		private void detach_tbl_Inventories(tbl_Inventory entity)
		{
			this.SendPropertyChanging();
			entity.tbl_USER = null;
		}
Beispiel #5
0
		private void attach_tbl_Inventories(tbl_Inventory entity)
		{
			this.SendPropertyChanging();
			entity.tbl_Item = this;
		}
Beispiel #6
0
        public static string Work(string usuario)
        {
            var FechaHoy = DateTime.Now;
            SessionDBDataContext dbWsim = new SessionDBDataContext();

            usuario = Desencriptar(usuario.Replace("Usuario=", ""));
            int UsuarioID = 0;
            try
            {
                UsuarioID = (from t in dbWsim.tbl_USERs
                             where t.Usr_Name.Equals(usuario)
                             select t.Usr_id).Single();

                var ConsultaSiYaTrabajo = (from t in dbWsim.tbl_Workdays
                                           where t.User_ID == UsuarioID
                                           && t.Workday_Date.Month == FechaHoy.Month
                                           && t.Workday_Date.Day == FechaHoy.Day
                                           && t.Workday_Date.Year == FechaHoy.Year
                                           select t.Workday_Date).Single();
                return "You already work commander, you can only work 1 time a day";
            }
            catch (Exception) { }

            var userInfo = (from t in dbWsim.View_UserInfos
                            where t.User_ID == UsuarioID
                                      select t).Single();
            int cantidadProducir = 0;

            switch (userInfo.Usr_EconomySkill)
            {
                case 1:
                    cantidadProducir = 100;
                    break;
                case 2:
                    cantidadProducir = 120;
                    break;
                case 3:
                    cantidadProducir = 140;
                    break;
                case 4:
                    cantidadProducir = 160;
                    break;
                case 5:
                    cantidadProducir = 180;
                    break;
                case 6:
                    cantidadProducir = 200;
                    break;
                case 7:
                    cantidadProducir = 220;
                    break;
                case 8:
                    cantidadProducir = 240;
                    break;
                case 9:
                    cantidadProducir = 260;
                    break;
                default:
                    cantidadProducir = 100;
                    break;
            }

            //Se resta el raw de la tabla inventarios que se cambia por el item  a producir
            try
            {
                var ItemIdRaw = (from r in dbWsim.tbl_Items
                               where r.Item_ID == userInfo.ItemToProduceID
                               select r.ItemIDRawProduce).Single();

                var restRaw = (from r in dbWsim.tbl_Inventories
                               where r.User_ID == userInfo.User_OwnerID
                               && r.Item_ID == ItemIdRaw
                               && r.Invtry_Item_Quality == userInfo.Company_Level
                               select r).Single();
                if (restRaw.Invtry_Item_Quantity >= cantidadProducir)
                    restRaw.Invtry_Item_Quantity -= cantidadProducir;
                else//No tiene el raw necesario para producir el item
                    return "The company doesnt have enought materials to produce " +userInfo.ItemNameToProduce;

                var produceItem = (from r in dbWsim.tbl_Inventories
                                   where r.User_ID == userInfo.User_OwnerID
                                   && r.Item_ID == userInfo.ItemToProduceID
                                   && r.Invtry_Item_Quality == userInfo.Company_Level
                                   select r).Single();
                produceItem.Invtry_Item_Quantity += cantidadProducir;

                dbWsim.SubmitChanges();
            }
            catch (Exception)
            {
                tbl_Inventory insertInvetry = new tbl_Inventory();
                insertInvetry.User_ID = userInfo.User_OwnerID;
                insertInvetry.Invtry_Item_Quantity += cantidadProducir;
                insertInvetry.Item_ID = userInfo.ItemToProduceID;
                insertInvetry.Invtry_Item_Quality = userInfo.Company_Level;
                dbWsim.tbl_Inventories.InsertOnSubmit(insertInvetry);
                dbWsim.SubmitChanges();
            }

            //El salario del empleado faltan los impuestos
            try
            {
                try
                {
                    var paysalary = (from t in dbWsim.tbl_Banks
                                     where t.User_ID == userInfo.User_OwnerID
                                     && t.Mny_ID == userInfo.MnyTypeID
                                     && t.Bank_Quantity > userInfo.Salary
                                     select t).Single();
                    paysalary.Bank_Quantity -= userInfo.Salary;
                }
                catch (Exception) { return "The company doesnt have enough resources to pay your salary"
                  +  " you can buy on the market"; }

                var insertBank = (from t in dbWsim.tbl_Banks
                                  where t.User_ID == userInfo.User_ID
                                  && t.Mny_ID == userInfo.MnyTypeID
                                  select t).Single();
                insertBank.Bank_Quantity += userInfo.Salary;

            }
            catch (Exception)
            {
                tbl_Bank banc = new tbl_Bank();
                banc.Bank_Quantity = userInfo.Salary;
                banc.Mny_ID = Convert.ToInt32(userInfo.MnyTypeID);
                banc.User_ID = userInfo.User_ID;
                dbWsim.tbl_Banks.InsertOnSubmit(banc);
                dbWsim.SubmitChanges();
            }

            var insertUsers = (from t in dbWsim.tbl_USERs
                            where t.Usr_id == userInfo.User_ID
                            select t).Single();
            insertUsers.Usr_Experience += 2;

            tbl_Workday insertWorkDay = new tbl_Workday();
            insertWorkDay.Company_ID = userInfo.Compny_ID;
            insertWorkDay.User_ID = userInfo.User_ID;
            insertWorkDay.Workday_Date = FechaHoy;

            var consultCuantasVecesTrabajado = (from t in dbWsim.tbl_Workdays
                                                where t.User_ID == userInfo.User_ID
                                                select t).Count();
            switch (consultCuantasVecesTrabajado)
            {
                case 0:
                    insertUsers.Usr_EconomySkill = 1;
                    insertUsers.Usr_TitleJob = "Assistant";
                    break;
                case 2:
                    insertUsers.Usr_EconomySkill = 2;
                    insertUsers.Usr_TitleJob = "Junior";
                    break;
                case 4:
                    insertUsers.Usr_EconomySkill = 3;
                    insertUsers.Usr_TitleJob = "Senior";
                    break;
                case 15:
                    insertUsers.Usr_EconomySkill = 4;
                    insertUsers.Usr_TitleJob = "Coordinator";
                    break;
                case 23:
                    insertUsers.Usr_EconomySkill = 5;
                    insertUsers.Usr_TitleJob = "Specialist";
                    break;
                case 32:
                    insertUsers.Usr_EconomySkill = 6;
                    insertUsers.Usr_TitleJob = "Expert";
                    break;
                case 54:
                    insertUsers.Usr_EconomySkill = 7;
                    insertUsers.Usr_TitleJob = "Master";
                    break;
                case 95:
                    insertUsers.Usr_EconomySkill = 8;
                    insertUsers.Usr_TitleJob = "Guru";
                    break;
                case 168:
                    insertUsers.Usr_EconomySkill = 9;
                    insertUsers.Usr_TitleJob = "Guru *";
                    break;
                default:

                    break;
            }

            try
            {
                DateTime diaAyer = DateTime.Now.AddDays(-1);
                var workingDaysInRow = (from t in dbWsim.tbl_Workdays
                                        where t.User_ID == userInfo.User_ID
                                        && t.Workday_Date.Day == diaAyer.Day
                                        select t.Workday_Date).Single();
                insertUsers.Usr_WorkDaysInRow++;

                if (insertUsers.Usr_WorkDaysInRow == 30)
                {

                }
            }
            catch(Exception){}
            dbWsim.tbl_Workdays.InsertOnSubmit(insertWorkDay);
            dbWsim.SubmitChanges();
            return "You succesfully work! come back tomorrow commander to work again.";
        }