Beispiel #1
0
 public static bool Create(Connection.Model.AllGoods AllGoodsInstance)
 {
     using (var context = new Connection.Model.PersianModel())
     {
         try
         {
             context.AllGoods.Add(AllGoodsInstance);
             context.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.ToString());
             return(false);
         }
     }
 }
Beispiel #2
0
 public static bool Update(Connection.Model.AllGoods ObjectName)
 {
     using (var context = new Connection.Model.PersianModel())
     {
         try
         {
             var Ins = context.AllGoods.Where(a => a.GoodsID == ObjectName.GoodsID).FirstOrDefault();
             Ins.ActDate     = ObjectName.ActDate;
             Ins.ArzID       = ObjectName.ArzID;
             Ins.BuyPrice    = ObjectName.BuyPrice;
             Ins.GoodsName   = ObjectName.GoodsName;
             Ins.OtherPrices = ObjectName.OtherPrices;
             Ins.ArzPrice    = ObjectName.ArzPrice;
             Ins.ArzName     = ObjectName.ArzName;
             context.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.ToString());
             return(false);
         }
     }
 }
Beispiel #3
0
        private void TTExcell_Click(object sender, EventArgs e)
        {
            try
            {
                if (PersianUI.MessageBoxes.CustomMessageForm.CustomMessageBox.Show("پيغام", "آيا از انجام اين كار مطمئن هستيد؟\n تمام داده هاي شما پاك خواهند شد و داده هاي جديد جايگزين خواهند شد\n در صورت انتخاب بلي منتظر بمانيد تا داده هاي شما پاك شود", "w") == DialogResult.Yes)
                {
                    if (Connection.CrudService.GoodsCrud.Delete() && Connection.CrudService.ArzCrud.Delete())
                    {
                        PersianUI.MessageBoxes.CustomMessageForm.CustomMessageBox.Show("پيغام", "اطلاعات ديتابيس با موفقيت پاك شدند");
                        OpenFileDialog ofImport = new OpenFileDialog();
                        ofImport.Title            = "Select file";
                        ofImport.InitialDirectory = @"c:\";
                        ofImport.FileName         = "";
                        ofImport.Filter           = "Excel Sheet(*.xlsx)|*.xlsx|All Files(*.*)|*.*";
                        ofImport.FilterIndex      = 1;
                        ofImport.RestoreDirectory = true;

                        if (ofImport.ShowDialog() == DialogResult.OK)
                        {
                            DataGridView dataGridView1 = new DataGridView();
                            String       name          = "Sheet1";
                            String       constr        = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                                                         ofImport.FileName +
                                                         ";Extended Properties='Excel 8.0;HDR=YES;';";

                            OleDbConnection con   = new OleDbConnection(constr);
                            OleDbCommand    oconn = new OleDbCommand("Select * From [" + name + "$]", con);
                            con.Open();
                            OleDbDataAdapter      sda  = new OleDbDataAdapter(oconn);
                            System.Data.DataTable data = new System.Data.DataTable();
                            sda.Fill(data);
                            List <DataRow> list = data.AsEnumerable().ToList();
                            dataGridView1.DataSource = list;
                            Dictionary <string, decimal>     AllArz      = new Dictionary <string, decimal>();
                            List <Connection.Model.AllGoods> ResultGoods = new List <Connection.Model.AllGoods>();
                            foreach (var item in list)
                            {
                                if (!AllArz.Any(a => a.Key == item.ItemArray[3].ToString()))
                                {
                                    AllArz.Add(item.ItemArray[3].ToString(), decimal.Parse(item.ItemArray[2].ToString()));
                                }
                                Connection.Model.AllGoods Res = new Connection.Model.AllGoods()
                                {
                                    ArzID       = 0,
                                    ArzPrice    = 0,
                                    ActDate     = item.ItemArray[1].ToString(),
                                    ArzName     = item.ItemArray[3].ToString(),
                                    BuyPrice    = decimal.Parse(item.ItemArray[5].ToString()),
                                    GoodsName   = item.ItemArray[4].ToString(),
                                    OtherPrices = decimal.Parse(item.ItemArray[6].ToString()),
                                };
                                ResultGoods.Add(Res);
                            }
                            foreach (var item in AllArz)
                            {
                                Connection.CrudService.ArzCrud.Create(new Connection.Model.Arz()
                                {
                                    ArzName = item.Key, Price = item.Value
                                });
                            }
                            var ArzRes = Connection.CrudService.ArzCrud.ReturnArz();
                            foreach (var item in ResultGoods)
                            {
                                Connection.CrudService.GoodsCrud.Create(new Connection.Model.AllGoods()
                                {
                                    ActDate = item.ActDate, ArzID = ArzRes.FirstOrDefault(a => a.ArzName == item.ArzName).ArzID, ArzName = item.ArzName, ArzPrice = ArzRes.FirstOrDefault(a => a.ArzName == item.ArzName).Price, BuyPrice = item.BuyPrice, GoodsName = item.GoodsName, OtherPrices = item.OtherPrices
                                });
                            }
                            PersianUI.MessageBoxes.CustomMessageForm.CustomMessageBox.Show("پيغام", "اطلاعات با موفقيت جايگذاري شدند");
                        }
                    }
                    else
                    {
                        PersianUI.MessageBoxes.CustomMessageForm.CustomMessageBox.Show("پيغام", "حذف اطلاعات با خطا مواجه شد", "e");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }