Exemplo n.º 1
0
        private void button23_Click(object sender, EventArgs e)
        {
            DBContext myDb = null;

            try
            {
                myDb = new DBContext();
                myDb.products.Load();
                var lst = myDb.products.ToList();
                if (lst.Count == 0)
                {
                    //لیست خالی
                }
                else
                {
                    bool flag = false;
                    myDb.superCategories.Load();
                    var lst1 = myDb.superCategories.ToList();
                    for (int i = 0; i < lst1.Count; i++)
                    {
                        if (lst1[i].Name == "")
                        {
                            flag = true;
                        }
                        if (!flag)
                        {
                            StoreModels.SuperCategory sc = new StoreModels.SuperCategory()
                            {
                                Name = "سوپر دسته"
                            };
                            myDb.save(sc);
                        }
                    }
                    myDb.categories.Load();
                    var lst2 = myDb.categories.ToList();
                    for (int i = 0; i < lst1.Count; i++)
                    {
                        if (lst2[i].Name == "دسته1")
                        {
                            flag = true;
                        }
                        if (!flag)
                        {
                            StoreModels.Category c = new StoreModels.Category()
                            {
                                Name = "کالا"
                            };
                            myDb.save(c);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            DBContext myDb = new DBContext();

            myDb.categories.Where(o => o.Name == "دسته1").Load();
            var cats = myDb.categories.ToList();

            StoreModels.Category c;
            if (cats.Count == 0)
            {
                c = new StoreModels.Category()
                {
                    Name = "دسته جدید"
                };
            }

            else
            {
                c = cats[0];
            }
            StoreModels.Product p = new StoreModels.Product()
            {
                Availability = 10,
                BuyPrice     = 1000,
                SellPrice    = 1500,
                Category     = c,
                Name         = "محصول1",
            };


            myDb.save(p);
        }
Exemplo n.º 3
0
        private void button3_Click(object sender, EventArgs e)
        {
            DBContext myDb = new DBContext();

            myDb.superCategories.Where(o => o.Name == "سوپر دسته1").Load();
            var scats = myDb.superCategories.ToList();

            StoreModels.SuperCategory sc;
            if (scats.Count == 0)
            {
                sc = new StoreModels.SuperCategory()
                {
                    Name = "سوپر دسته جدید"
                }
            }
            ;
            else
            {
                sc = scats[0];
            }

            StoreModels.Category c = new StoreModels.Category()
            {
                Name          = "دسته1",
                SuperCategory = sc
            };

            myDb.save(c);
        }
Exemplo n.º 4
0
        public void sell(List <ProductTransactionItem> pti, DateTime date, string not = null, bool isPaid = true, Contact con = null, Check chk = null)
        {
            DateTime?paydate = null;

            if (isPaid)
            {
                paydate = DateTime.Now;
            }
            ProductTransaction pt = new ProductTransaction()
            {
                CreationDate = date,
                PaymentDate  = paydate,
                Check        = chk,
                Contact      = con,
                Note         = not,
            };
            DBContext myDBContext = new DBContext();

            foreach (ProductTransactionItem item in pti)
            {
                pt.items.Add(item);
                myDBContext.products.Attach(item.Product); //association with product and dbcontext
            }

            myDBContext.save(pt);
        }
Exemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            StoreModels.SuperCategory sc = new StoreModels.SuperCategory()
            {
                Name = "سوپر دسته1"
            };
            DBContext myDb = new DBContext();

            myDb.save(sc);
        }
Exemplo n.º 6
0
        private void button5_Click(object sender, EventArgs e)
        {
            StoreModels.Contact con = new StoreModels.Contact()
            {
                Name  = "Arash",
                Type  = StoreModels.Contact.Types.Person,
                Phone = "09355000000"
            };
            DBContext myDB = new DBContext();

            myDB.save(con);
        }
Exemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            StoreModels.Check ch = new StoreModels.Check()
            {
                Date         = DateTime.Now,
                Price        = 2000,
                VosoolStatus = StoreModels.Check.VosoolStatuses.pishAzMoed,
                BankBranch   = "1234"
            };

            DBContext myDb = new DBContext();

            myDb.save(ch);
        }
Exemplo n.º 8
0
 private void buttonX2_Click(object sender, EventArgs e)
 {
     if (textBox1.Text == "" || textBox3.Text == "" || textBox4.Text == "")
     {
         MessageBox.Show("لطفا تمام اطلاعات را تکمیل کنید", "خطا");
         return;
     }
     try
     {
         long buyPrice         = long.Parse(textBox3.Text);
         long sellPrice        = long.Parse(textBox4.Text);
         int  avail            = (int)numericUpDown1.Value;
         StoreModels.Product p = new StoreModels.Product()
         {
             Name         = textBox1.Text,
             BarCode      = textBox2.Text,
             BuyPrice     = buyPrice,
             SellPrice    = sellPrice,
             Availability = avail,
             Category     = null
         };
         DBContext myDb = new DBContext();
         myDb.save(p);
         this.Close();
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         String s = "خطا در ذخیره اطلاعات در پایگاه داده\nمشخصات فنی:\n";
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                 s = s + "\nProperty: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage;
             }
         }
         MessageBox.Show(s);
     }
     catch (Exception ex)
     {
         MessageBox.Show("خطایی رخ داد\n" + ex.Message);
     }
 }
Exemplo n.º 9
0
 private void button6_Click(object sender, EventArgs e)
 {
     try
     {
         StoreModels.MoneyTransaction mt = new StoreModels.MoneyTransaction()
         {
             CreationDate = DateTime.Now,
             IsPersonal   = true,
             TotalPrice   = 10000,
             Type         = StoreModels.MoneyTransaction.MTTypes.Hazine
         };
         DBContext myDB = new DBContext();
         myDB.save(mt);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 10
0
 private void button7_Click(object sender, EventArgs e)
 {
     try
     {
         StoreModels.FinancialTransaction ft = new StoreModels.FinancialTransaction()
         {
             CreationDate = DateTime.Now,
             IsPersonal   = true,
             TotalPrice   = 10000,
             Type         = StoreModels.FinancialTransaction.FTTypes.Talab,
             PayType      = StoreModels.Transaction.PaymentTypes.Naghd
         };
         DBContext myDB = new DBContext();
         myDB.save(ft);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         //throw;
     }
 }