Esempio n. 1
0
        private async void buttonUsersDel_Click(object sender, EventArgs e)
        {
            if (dataGridViewUsers.SelectedRows.Count > 0)
            {
                int  index     = dataGridViewUsers.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridViewUsers[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }
                UsersLogin user = db.UsersLogins.Find(id);
                if (user.Admin == true)
                {
                    MenedjerInformation mInfo = db.MenedjersInformations.FirstOrDefault(mI => mI.UserLoginId == user.Id);
                    if (mInfo != null)
                    {
                        db.MenedjersInformations.Remove(mInfo);
                    }
                }
                else
                {
                    CustomerInformation cInfo = db.CustomersInformations.FirstOrDefault(cI => cI.UserLoginId == user.Id);
                    if (cInfo != null)
                    {
                        db.CustomersInformations.Remove(cInfo);
                    }
                }

                db.UsersLogins.Remove(user);
                await db.SaveChangesAsync();

                MessageBox.Show("object deleted");
            }
        }
Esempio n. 2
0
        private async void buttonMenegerDel_Click(object sender, EventArgs e)
        {
            if (dataGridViewMenegers.SelectedRows.Count > 0)
            {
                int  index     = dataGridViewMenegers.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridViewMenegers[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                MenedjerInformation prod = db.MenedjersInformations.Find(id);
                db.MenedjersInformations.Remove(prod);
                await db.SaveChangesAsync();

                MessageBox.Show("object deleted");
            }
        }
Esempio n. 3
0
        private async void buttonMenegerChange_Click(object sender, EventArgs e)
        {
            if (dataGridViewMenegers.SelectedRows.Count > 0)
            {
                int  index     = dataGridViewMenegers.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridViewMenegers[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                MenedjerInformation prod        = db.MenedjersInformations.Find(id);
                MenegerInfoForm     pFormChange = new MenegerInfoForm();
                string[]            spliter     = prod.DataOfBirth.Split(',');
                pFormChange.dateTimeCreated.Value     = new DateTime(Convert.ToInt32(spliter[2]), Convert.ToInt32(spliter[1]), Convert.ToInt32(spliter[0]));
                pFormChange.numericUpDownUserID.Value = Convert.ToDecimal(prod.UserLoginId);
                pFormChange.textBoxAddres.Text        = prod.Address;
                pFormChange.textBoxPhone.Text         = prod.PhoneNumber;
                pFormChange.textBoxFullName.Text      = prod.FullName;
                pFormChange.textBoxStatus.Text        = prod.Status;
                DialogResult result = pFormChange.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }
                prod.Status      = pFormChange.textBoxStatus.Text;
                prod.Address     = pFormChange.textBoxAddres.Text;
                prod.FullName    = pFormChange.textBoxFullName.Text;
                prod.PhoneNumber = pFormChange.textBoxPhone.Text;
                prod.UserLoginId = Convert.ToInt32(pFormChange.numericUpDownUserID.Value);
                prod.DataOfBirth = pFormChange.dateTimeCreated.Value.Day + "," + pFormChange.dateTimeCreated.Value.Month + "," + pFormChange.dateTimeCreated.Value.Year;

                await db.SaveChangesAsync();

                dataGridViewMenegers.Refresh();
                MessageBox.Show("object updated");
            }
        }
Esempio n. 4
0
            public static async void FillDataBase()
            {
                List <string> ReferenceByTelemart = new List <string>()
                {
                    "https://telemart.ua/ua/processor/",
                    "https://telemart.ua/ua/motherboard/",
                    "https://telemart.ua/ua/videocard/",
                    "https://telemart.ua/ua/ram/",
                    "https://telemart.ua/ua/hard-drive/",
                    "https://telemart.ua/ua/case/",
                    "https://telemart.ua/ua/powersuply/",

                    "https://telemart.ua/ua/ua/mouse/",
                    "https://telemart.ua/ua/keyboards/",
                    "https://telemart.ua/ua/kovriki/",
                    "https://telemart.ua/ua/microphones/",
                    "https://telemart.ua/ua/earphones/",
                    "https://telemart.ua/ua/web-cam/",
                    "https://telemart.ua/ua/hdmi-dvi-vga-cables/",

                    "https://telemart.ua/ua/monitors/filter/for-office-tasks/",
                    "https://telemart.ua/ua/monitors/filter/for-game/",
                    "https://telemart.ua/ua/monitors/filter/work-with-graphics/",
                    "https://telemart.ua/ua/monitors/",

                    "https://telemart.ua/ua/laptops/filter/1920x1080/",
                    "https://telemart.ua/ua/laptops/filter/geforce-1080/geforce-1660-ti/geforce-2060/geforce-2070/geforce-2080/",
                    "https://telemart.ua/ua/laptops/",

                    "https://telemart.ua/ua/pc/filter/t-gaming/",
                    "https://telemart.ua/ua/pc/filter/t-ultra/",
                };
                List <string> CategoriesNameForReferance = new List <string>()
                {
                    "Processor", "Motherboard", "Videocard", "Ram", "HardDrive", "Case", "Powersuply",
                    "Mouse", "Keyboard", "Capet", "Microphone", "Headset", "Camera", "Cabel",
                    "MonitorOfice", "MonitorGame", "MonitorDisign", "MonitorAll",
                    "NoutbookOfice", "NoutbookGame", "NoutbookAll",
                    "PcGame", "PcUltra"
                };

                using (DataBaseIM db = new DataBaseIM())
                {
                    UsersLogin uL = new UsersLogin();
                    uL.Admin    = true;
                    uL.Login    = "******";
                    uL.Password = "******";
                    uL.Mail     = "*****@*****.**";
                    MenedjerInformation mInfo = new MenedjerInformation();
                    mInfo.UserLogin = uL;
                    db.UsersLogins.Add(uL);
                    db.MenedjersInformations.Add(mInfo);
                    Console.WriteLine("Менеджер Admin доданий в базу даних\n");
                    for (int l = 0; l < ReferenceByTelemart.Count; l++)
                    {
                        List <Product> productList = new List <Product>();
                        var            parser      = new Parser();
                        var            result      = parser.GetInfo(ReferenceByTelemart[l]).Result;
                        try
                        {
                            for (int i = 0; i < result.Title.Count; i++)
                            {
                                Product p = new Product();
                                //Categoty
                                p.ProductCategory = CategoriesNameForReferance[l];

                                p.Title = result.Title[i];
                                Regex  regex = new Regex(@"\s*грн");
                                string clear = regex.Replace(result.Price[i], "");
                                regex   = new Regex(@"\s+");
                                clear   = regex.Replace(clear, "");
                                p.Price = clear;

                                //Reference on image
                                p.ImageData = result.Images[i];
                                //Characteristics
                                string[] s = Regex.Split(result.Characteristics[i], "</div>");
                                s = Regex.Split(s[1], "<br>");
                                List <Characteristic> listCharact = new List <Characteristic>();
                                foreach (var iteDataBaseIM in s)
                                {
                                    Characteristic ch     = new Characteristic();
                                    string         target = "";
                                    regex = new Regex(@"<[^>]*>");
                                    string withoutTags = regex.Replace(iteDataBaseIM, target);
                                    regex = new Regex(@"^\s+");
                                    clear = regex.Replace(withoutTags, target);
                                    ch.CharacteristicString = clear;
                                    listCharact.Add(ch);
                                }
                                p.Characteristics = listCharact;
                                productList.Add(p);
                            }
                            db.Products.AddRange(productList);
                            await db.SaveChangesAsync();

                            Console.WriteLine("Link : " + l + " uploaded");
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Eror by: " + l);
                        }
                    }
                    Console.WriteLine("All links uploaded successfully");
                }
            }
Esempio n. 5
0
        private async void buttonUsersAdd_Click(object sender, EventArgs e)
        {
            UserForm     uFAdd = new UserForm();
            DialogResult ress;

            while (true)
            {
                ress = uFAdd.ShowDialog(this);
                if (ress == DialogResult.Cancel)
                {
                    return;
                }
                if (CheckUser(uFAdd.EmailTextBox.Text))
                {
                    UsersLogin user = new UsersLogin();
                    user.Login    = uFAdd.LoginTextBox.Text;
                    user.Password = uFAdd.PasswordTextBox.Text;
                    user.Mail     = uFAdd.EmailTextBox.Text;
                    user.Admin    = uFAdd.AdminCheck.Checked;
                    db.UsersLogins.Add(user);
                    await db.SaveChangesAsync();

                    MessageBox.Show("New Object Added");
                    if (user.Admin == true)
                    {
                        MenegerInfoForm pFormAdd = new MenegerInfoForm();
                        DialogResult    result;
                        while (true)
                        {
                            result = pFormAdd.ShowDialog(this);

                            if (result == DialogResult.Cancel)
                            {
                                return;
                            }
                            if (CheckUser(pFormAdd.textBoxFullName.Text, pFormAdd.textBoxAddres.Text, pFormAdd.textBoxPhone.Text))
                            {
                                MenedjerInformation prod = new MenedjerInformation();
                                prod.Status      = pFormAdd.textBoxStatus.Text;
                                prod.Address     = pFormAdd.textBoxAddres.Text;
                                prod.FullName    = pFormAdd.textBoxFullName.Text;
                                prod.PhoneNumber = pFormAdd.textBoxPhone.Text;
                                UsersLogin us = db.UsersLogins.FirstOrDefault(u => (u.Login == user.Login || u.Mail == user.Mail) && u.Password == user.Password);
                                if (us != null)
                                {
                                    prod.UserLoginId = us.Id;
                                }
                                prod.DataOfBirth = pFormAdd.dateTimeCreated.Value.Day + "," + pFormAdd.dateTimeCreated.Value.Month + "," + pFormAdd.dateTimeCreated.Value.Year;
                                db.MenedjersInformations.Add(prod);
                                await db.SaveChangesAsync();

                                MessageBox.Show("New Object Added");
                                return;
                            }
                        }
                    }
                    else if (user.Admin == false)
                    {
                        CustumerInfoForm pFormAdd = new CustumerInfoForm();
                        DialogResult     result;
                        while (true)
                        {
                            result = pFormAdd.ShowDialog(this);

                            if (result == DialogResult.Cancel)
                            {
                                return;
                            }
                            if (CheckUser(pFormAdd.textBoxFullName.Text, pFormAdd.textBoxAddres.Text, pFormAdd.textBoxPhone.Text))
                            {
                                CustomerInformation prod = new CustomerInformation();

                                prod.Address     = pFormAdd.textBoxAddres.Text;
                                prod.ContactFio  = pFormAdd.textBoxFullName.Text;
                                prod.Phone       = pFormAdd.textBoxPhone.Text;
                                prod.UserLoginId = Convert.ToInt32(pFormAdd.numericUpDownUserID.Value);
                                prod.DataOfBirth = pFormAdd.dataTimeBirth.Value.Day + "," + pFormAdd.dataTimeBirth.Value.Month + "," + pFormAdd.dataTimeBirth.Value.Year;
                                UsersLogin us = db.UsersLogins.FirstOrDefault(u => (u.Login == user.Login || u.Mail == user.Mail) && u.Password == user.Password);
                                if (us != null)
                                {
                                    prod.UserLoginId = us.Id;
                                }
                                db.CustomersInformations.Add(prod);
                                await db.SaveChangesAsync();

                                MessageBox.Show("New Object Added");
                                return;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        private async void buttonMenegerAdd_Click(object sender, EventArgs e)
        {
            MenegerInfoForm pFormAdd = new MenegerInfoForm();
            DialogResult    result;

            while (true)
            {
                result = pFormAdd.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (CheckUser(pFormAdd.textBoxFullName.Text, pFormAdd.textBoxAddres.Text, pFormAdd.textBoxPhone.Text))
                {
                    MenedjerInformation prod = new MenedjerInformation();
                    prod.Status      = pFormAdd.textBoxStatus.Text;
                    prod.Address     = pFormAdd.textBoxAddres.Text;
                    prod.FullName    = pFormAdd.textBoxFullName.Text;
                    prod.PhoneNumber = pFormAdd.textBoxPhone.Text;
                    prod.UserLoginId = Convert.ToInt32(pFormAdd.numericUpDownUserID.Value);
                    prod.DataOfBirth = pFormAdd.dateTimeCreated.Value.Day + "," + pFormAdd.dateTimeCreated.Value.Month + "," + pFormAdd.dateTimeCreated.Value.Year;

                    UsersLogin uL = db.UsersLogins.FirstOrDefault(u => u.Id == prod.UserLoginId);
                    if (uL == null)
                    {
                        MessageBox.Show("To add manager information you need to create an account");
                        UserForm     uFAdd = new UserForm();
                        DialogResult ress;
                        while (true)
                        {
                            ress = uFAdd.ShowDialog(this);
                            if (ress == DialogResult.Cancel)
                            {
                                return;
                            }
                            if (CheckUser(uFAdd.EmailTextBox.Text))
                            {
                                UsersLogin user = new UsersLogin();

                                user.Login    = uFAdd.LoginTextBox.Text;
                                user.Password = uFAdd.PasswordTextBox.Text;
                                user.Mail     = uFAdd.EmailTextBox.Text;
                                user.Admin    = true;

                                db.UsersLogins.Add(user);
                                prod.UserLogin = user;
                                db.MenedjersInformations.Add(prod);
                                await db.SaveChangesAsync();

                                MessageBox.Show("New manager and information about him");
                                return;
                            }
                        }
                    }
                    else
                    {
                        db.MenedjersInformations.Add(prod);
                        await db.SaveChangesAsync();

                        MessageBox.Show("New Object Added");
                        return;
                    }
                }
            }
        }
Esempio n. 7
0
 private void loginButton_MouseClick(object sender, MouseEventArgs e)
 {
     try
     {
         using (DataBaseIM db = new DataBaseIM())
         {
             UsersLogin user = db.UsersLogins.FirstOrDefault(u => (u.Login == loginName.Text || u.Mail == loginName.Text) && u.Password == loginPassword.Text);
             if (user != null)
             {
                 CustomerInformation cInfo = db.CustomersInformations.FirstOrDefault(cI => cI.UserLoginId == user.Id);
                 if (cInfo != null)
                 {
                     if (checkBoxUserSave.Checked)
                     {
                         try
                         {
                             SaveSettings();
                         }
                         catch (Exception exd)
                         {
                             MessageBox.Show("Error Server: " + exd);
                         }
                     }
                     this.Hide();
                     CustomerForm cF = new CustomerForm(cInfo);
                     cF.Show();
                 }
                 else
                 {
                     MenedjerInformation mInfo = db.MenedjersInformations.FirstOrDefault(mI => mI.UserLoginId == user.Id);
                     if (mInfo != null)
                     {
                         if (checkBoxUserSave.Checked)
                         {
                             try
                             {
                                 SaveSettings();
                             }
                             catch (Exception exd)
                             {
                                 MessageBox.Show("Error Server: " + exd);
                             }
                         }
                         this.Hide();
                         AdminForm aF = new AdminForm();
                         aF.Show();
                     }
                     else
                     {
                         MessageBox.Show("NOT found");
                     }
                 }
             }
             else
             {
                 MessageBox.Show("No such user found");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error Server: " + ex);
     }
 }