private void New_Click(object sender, EventArgs e)
        {
            Company_ProjectEntities company_Project = new Company_ProjectEntities();

            try
            {
                string manf   = dateTimePicker1.Value.ToShortDateString();
                string exp    = dateTimePicker2.Value.ToShortDateString();
                var    itNAme = (from i in company_Project.items
                                 where i.name == comboBox2.Text && i.size == textBox3.Text &&
                                 i.ManifuctureDate == manf && i.expireDate == exp
                                 select i).First();

                Storage_item si = new Storage_item();
                si.amount  = int.Parse(textBox4.Text);
                si.Item_ID = int.Parse(textBox1.Text);

                var st = (from i in company_Project.Storages
                          where i.name == comboBox1.Text
                          select i).First();
                si.Storage_ID = st.ID_storage;
                company_Project.Storage_item.Add(si);
                company_Project.SaveChanges();
                MessageBox.Show($"New {comboBox2.Text} added in {comboBox1.Text}.");
            }
            catch
            {
                item   it  = new item();
                Random rnd = new Random();
                textBox1.Text = rnd.Next().ToString();
                it.ID_item    = int.Parse(textBox1.Text);
                try
                {
                    var itNAme = (from i in company_Project.items where i.name == comboBox2.Text select i).First();
                    MessageBox.Show("this name is exist.");
                }
                catch
                {
                    it.name            = comboBox2.Text;
                    it.size            = textBox3.Text;
                    it.ManifuctureDate = dateTimePicker1.Value.ToShortDateString();
                    it.expireDate      = dateTimePicker2.Value.ToShortDateString();

                    Storage_item si = new Storage_item();
                    if (textBox4.Text == String.Empty)
                    {
                        MessageBox.Show("item have to have ammount");
                    }
                    else
                    {
                        si.amount = int.Parse(textBox4.Text);
                    }

                    si.Item_ID = int.Parse(textBox1.Text);

                    var st = (from i in company_Project.Storages
                              where i.name == comboBox1.Text
                              select i).First();
                    si.Storage_ID = st.ID_storage;
                    company_Project.Storage_item.Add(si);
                    company_Project.items.Add(it);
                    company_Project.SaveChanges();
                    MessageBox.Show($"New {comboBox2.Text} added in {comboBox1.Text}.");
                }
            }
        }
Beispiel #2
0
        private void Save_Recipt_Click(object sender, EventArgs e)
        {
            Company_ProjectEntities company_Project = new Company_ProjectEntities();

            for (int a = 0; a < dt.Rows.Count; a++)
            {
                Permission per = new Permission();
                per.permission_ID   = int.Parse(textBox1.Text);
                per.typePermission  = "rec";
                per.Date_permission = dateTimePicker1.Value.ToShortDateString();

                string st_name = dt.Rows[a][0].ToString();
                var    st      = (from i in company_Project.Storages where i.name == st_name select i).First();
                per.stroage_id = st.ID_storage;

                string it_name = dt.Rows[a][1].ToString();
                var    it      = (from i in company_Project.items where i.name == it_name select i).First();
                per.item_id = it.ID_item;

                per.amount_item = int.Parse(dt.Rows[a][2].ToString());

                if (listBox1.SelectedItem == null)
                {
                    MessageBox.Show("select supplier"); break;
                }
                else
                {
                    string newper = listBox1.SelectedItem.ToString();
                    var    sup    = (from q in company_Project.Customers_Suppliers
                                     where q.name == newper && q.type == "Sup" select q).First();
                    per.name_id = sup.ID;
                }

                per.expireDate = dateTimePicker4.Value.ToShortDateString();
                per.Comment    = textBox4.Text;

                company_Project.Permissions.Add(per);
                company_Project.SaveChanges();


                try
                {
                    var check = (from i in company_Project.Storage_item
                                 where i.Storage_ID == st.ID_storage && i.Item_ID == it.ID_item
                                 select i).First();
                    check.amount += int.Parse(dt.Rows[a][2].ToString());
                }
                catch
                {
                    Storage_item st_it = new Storage_item();
                    st_it.Storage_ID = st.ID_storage;
                    st_it.Item_ID    = it.ID_item;
                    st_it.amount     = int.Parse(dt.Rows[a][2].ToString());
                    company_Project.Storage_item.Add(st_it);
                }

                company_Project.SaveChanges();
            }

            MessageBox.Show("items added");
        }