コード例 #1
0
ファイル: AddSellerForm.cs プロジェクト: Pavel228322/mywork
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text == "" || textBox3.Text == "")
                {
                    MessageBox.Show("Введите данные");
                    return;
                }
                Prodavets p = new Prodavets();
                p.FullName = textBox1.Text;
                p.Phone    = textBox3.Text;
                db.Prodavets.Add(p);
                db.SaveChanges();

                SystemUsers u = new SystemUsers();
                u.IdProdavets = p.idprodavets;
                u.Login       = textBox2.Text;
                u.Password    = textBox4.Text;
                db.SystemUsers.Add(u);
                db.SaveChanges();
                MessageBox.Show("Готово. Сохраните логин и пароль: " + u.Login + " " + u.Password);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
                this.Close();
            }
        }
コード例 #2
0
        public bool Register(string username, string password, int clear)
        {
            string hash  = password + "a6s8d";
            var    konto = new DBKonto()
            {
                Login = username, Haslo = md5Hash.GetMD5Hash(hash), Salt = "a6s8d", Clear = clear, Class_Haslo = 1, Class = 1, Class_Login = 1, Class_salt = 1
            };

            ctx.Konto.Add(konto);
            ctx.SaveChanges();
            int?id = ctx.Konto.Where(c => c.Login.Equals(username)).First().ID;
            var kl = new DBKlient()
            {
                Imie = username, Nazwisko = username, Adres = username + " 11", Class_Adres = 1, Class_Imie = 1, Class_Nazwisko = 1, Class = 1, ID_Konto = id
            };

            ctx.Klient.Add(kl);
            DBPracownik p;

            if (clear > 1)
            {
                p = new DBPracownik()
                {
                    Imie = username, Nazwisko = username, Class_Imie = 1, Class_Nazwisko = 1, Class = 1, ID_Konto = id, Data_zaczecia = DateTime.Now, Class_Data_zaczecia = 1, Stanowisko = "Test", Class_Stanowisko = 1
                };
                ctx.Pracownik.Add(p);
            }

            ctx.SaveChanges();
            return(true);
        }
コード例 #3
0
ファイル: SellerForm.cs プロジェクト: Pavel228322/mywork
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var             carNum   = dataGridView1.SelectedCells[0].Value;
                var             id       = (dataGridView2.SelectedCells[0].Value).ToString();
                var             clientId = db.Pokupatel.FirstOrDefault(x => x.FullName == id).idPocupatel;
                AppData.Prodaji p        = new AppData.Prodaji();
                AppData.Prodaji p2       = new AppData.Prodaji();
                p.SeleDate = DateTime.Now;
                p.CarNum   = carNum.ToString();
                p.Seller   = UserData.prodavets.idprodavets;
                p.Buyer    = clientId;


                var car = db.har_avto.FirstOrDefault(x => x.CarNum == carNum.ToString());
                car.Status = "Продан";

                db.Prodaji.Add(p);
                db.SaveChanges();
                initCars();
                MessageBox.Show("Автомобиль " + carNum.ToString() + " продан клиенту " + db.Pokupatel.FirstOrDefault(x => x.FullName == id).FullName);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
コード例 #4
0
        //[HttpPost]
        //public string BuyBook(Order order)
        //{
        //    order.Date = DateTime.Now;
        //    db.Orders.Add(order);
        //    db.SaveChanges();
        //    return "Спасибо," + order.Person + "за покупку!";

        //}

        public ActionResult BuyBook(int id)
        {
            Book b = db.Books.Find(id);

            if (b != null)
            {
                var UserId = int.Parse(User.Identity.Name);
                b.UserId = UserId;
                db.SaveChanges();

                db.Orders.Add(new Order {
                    UserId = UserId, BookId = b.Id, Date = DateTime.Now, BookName = b.Name
                });
                db.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public bool InsertarUsuario(TUsuario usuario)
        {
            bool result = false;

            using (DataBaseModel context = new DataBaseModel())
            {
                context.TUsuario.Add(usuario);
                context.SaveChanges();
            }

            return(result);
        }
コード例 #6
0
 public void AddUser(User user)
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         context.Set <UserDataModel>()
         .Add(new UserDataModel()
         {
             Username = user.Username, Email = user.Email, Password = user.Password, FullName = user.Fullname
         });
         context.SaveChanges();
     }
 }
コード例 #7
0
        public static void ChangeSettings(int userId, SettingModel model)
        {
            using (var db = new DataBaseModel())
            {
                var user = db.Users.FirstOrDefault(u => u.Id == userId);

                if (user.Password != model.Password)
                {
                    throw new SettingsException("Password not match");
                }

                user.Password = model.NewPassword;
                db.SaveChanges();
            }
        }
コード例 #8
0
 //TODO: for now this only saves the changed item to ItemDataModels table
 //nothing is written for categorizations.
 //Once categoraziation is sorted out need to add extra logic
 public void UpdateItem(Item UpdatedItem)
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         var itemToUpdate = context.Set <ItemDataModel>()
                            .FirstOrDefault(x => x.ItemId == UpdatedItem.ItemId);
         //TODO: I believe this can be written in more SOLID style
         //Using explicit/implicit type conversion operators
         //Didn't have the time to research this
         itemToUpdate.Name     = UpdatedItem.Name;
         itemToUpdate.Category = UpdatedItem.Category;
         itemToUpdate.Price    = UpdatedItem.Price;
         context.SaveChanges();
     }
 }
コード例 #9
0
        public static void BuyBook(int UserId, int BookId)
        {
            using (var context = new DataBaseModel())
            {
                var order = new Order
                {
                    BookId = BookId,
                    UserId = UserId,
                    Date   = DateTime.Now
                };


                context.Orders.Add(order);
                context.SaveChanges();
            }
        }
コード例 #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
            Regex r = new Regex(@"[АВЕКМНОРСТУХABEKMHOPCTYX]\d{3}[АВЕКМНОРСТУХABEKMHOPCTYX]{2}\d{2,3}$");

            if (!r.IsMatch(textBox1.Text))
            {
                MessageBox.Show("Введите корректный номер авто");
                return;
            }
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" ||
                textBox5.Text == "" || textBox8.Text == "" || textBox9.Text == "" || textBox11.Text == "" ||
                textBox6.Text == "" || textBox7.Text == "" || textBox10.Text == "")
            {
                MessageBox.Show("Введите все данные");
                return;
            }


            har_avto a = new har_avto();

            a.CarNum       = textBox1.Text;
            a.Price        = Decimal.Parse(textBox2.Text);
            a.Mileage      = Convert.ToInt32(textBox3.Text);
            a.Color        = textBox4.Text;
            a.Firm         = textBox5.Text;
            a.Model        = textBox6.Text;
            a.FuelType     = textBox7.Text;
            a.Power        = Convert.ToInt32(textBox8.Text);
            a.EngineVolume = Decimal.Parse(textBox9.Text);
            a.Year         = Convert.ToInt32(textBox10.Text);
            a.Country      = textBox11.Text;
            a.Description  = richTextBox1.Text;
            a.CarImg       = imgByte;
            db.har_avto.Add(a);
            db.SaveChanges();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #11
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (CheckNames(LastName.Text, FirstName.Text, MiddleName.Text) & CheckEmail(Email.Text) & CheckPassword(Password.Text))
     {
         AutentnData data = new AutentnData()
         {
             Email = Email.Text, Password = Password.Text
         };
         db.UserInfoes.Add(new UserInfo
         {
             LName       = LastName.Text,
             FName       = FirstName.Text,
             MName       = MiddleName.Text,
             AutentnData = data
         });
         db.SaveChanges();
         Hide();
     }
 }
コード例 #12
0
        public LoginSession CreateNewSession(User user)
        {
            using (DataBaseModel context = new DataBaseModel())
            {
                var userDataModel = context.Set <UserDataModel>()
                                    .FirstOrDefault(x => x.Username == user.Username);

                var loginSessionDataModel = context.Set <LoginSessionDataModel>()
                                            .Add(new LoginSessionDataModel()
                {
                    SessionID = Guid.NewGuid(),
                    User      = userDataModel
                });
                context.SaveChanges();
                return(new LoginSession()
                {
                    SessionID = loginSessionDataModel.SessionID,
                    Username = userDataModel.Username
                });
            }
        }
コード例 #13
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = null;
                using (var db = new DataBaseModel())
                {
                    user = db.Users.FirstOrDefault(u => u.Name == model.Name);
                }
                if (user == null)
                {
                    // создаем нового пользователя
                    using (var db = new DataBaseModel())
                    {
                        db.Users.Add(new User {
                            Name = model.Name, Email = model.Email, Password = model.Password
                        });
                        db.SaveChanges();

                        user = db.Users.Where(u => u.Name == model.Name && u.Password == model.Password).FirstOrDefault();
                    }
                    // если пользователь удачно добавлен в бд
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(user.Id.ToString(), true);
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }



            return(View(model));
        }
コード例 #14
0
        public int AddItems(IEnumerable <Item> items, Shop shop, string username)
        {
            using (DataBaseModel context = new DataBaseModel())
            {
                ShopDataModel shopDataModel = context.Set <ShopDataModel>()
                                              .Select(x => x)
                                              .Where(x => x.Name == shop.Name && x.Location == shop.Location)
                                              .FirstOrDefault() ?? new ShopDataModel()
                {
                    Location = shop.Location, Name = shop.Name
                };

                UserDataModel userDataModel = context.Set <UserDataModel>()
                                              .Select(x => x).Where(x => x.Username == username).FirstOrDefault();
                if (userDataModel == null)
                {
                    throw new System.Exception(Properties.Resources.UserNotFound);
                }

                ReceiptDataModel receiptDataModel = new ReceiptDataModel()
                {
                    Shop = shopDataModel, User = userDataModel, Total = 0
                };
                receiptDataModel.Items = new List <ItemDataModel>();
                foreach (Item item in items)
                {
                    receiptDataModel.Items.Add(new ItemDataModel()
                    {
                        Receipt = receiptDataModel, Price = item.Price, Name = item.Name, Category = item.Category
                    });
                    receiptDataModel.Total += item.Price;
                }
                context.Set <ReceiptDataModel>().Add(receiptDataModel);
                context.SaveChanges();
                return(receiptDataModel.ReceiptId);
            }
        }
コード例 #15
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
         {
             MessageBox.Show("Введите данные");
             return;
         }
         Pokupatel p = new Pokupatel();
         p.FullName = textBox1.Text;
         p.Address  = textBox2.Text;
         p.Phone    = textBox3.Text;
         db.Pokupatel.Add(p);
         db.SaveChanges();
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message);
         this.Close();
     }
 }
コード例 #16
0
        public ActionResult newBook(NewBookModel model)
        {
            var UserId = int.Parse(User.Identity.Name);


            if (ModelState.IsValid)
            {
                Book book = null;
                //using (var db = new DataBaseModel())
                //{
                //    book = db.Books.FirstOrDefault(u => u.Name == model.Name);
                //}
                //if (book == null)
                //{
                // создаем новую книгу
                using (var db = new DataBaseModel())
                {
                    db.Books.Add(new Book {
                        Name = model.Name, Autor = model.Autor, Price = model.Price, UserId = UserId
                    });
                    db.SaveChanges();
                }
                // если пользователь удачно добавлен в бд
                //if (book != null)
                //{
                return(RedirectToAction("Buy", "Home"));
                //}

                //}
                //else
                //{
                //    ModelState.AddModelError("", "Такая книга уже существует");
                //}
            }
            return(View(model));
        }