Beispiel #1
0
 private List <Result> SearchResults(string op, string name, DateTime sdate, DateTime edate)
 {
     try
     {
         using (WareHouseEntities en = new WareHouseEntities())
         {
             var lstInOut = en.InOuts.Include(p => p.Material)
                            .Where(x => x.Material.Name.Contains(name))
                            .Where(x => x.Date >= sdate && x.Date <= edate);
             if (op == "入库")
             {
                 lstInOut = lstInOut.Where(x => x.IsIn);
             }
             else
             {
                 lstInOut = lstInOut.Where(x => !x.IsIn);
             }
             return(lstInOut.Select(x => new Result()
             {
                 Type = op,
                 Name = x.Material.Name,
                 Price = x.Material.Price,
                 Quantity = x.Quantity,
                 Date = x.Date
             }).ToList());
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(new List <Result>());
     }
 }
Beispiel #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string name = this.listBox1.SelectedItem.ToString();

            try
            {
                this.btnDelete.Enabled = false;
                using (WareHouseEntities en = new WareHouseEntities())
                {
                    Material m  = en.Materials.First(x => x.Name == name);
                    int      id = m.ID;
                    foreach (InOut io in en.InOuts
                             .Where(x => x.MID == id))
                    {
                        en.InOuts.Remove(io);
                    }
                    en.SaveChanges();

                    en.Materials.Remove(m);
                    en.SaveChanges();
                }
                this.DisplayAllMaterials();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
 private void DisplayAllMaterials()
 {
     using (WareHouseEntities en = new WareHouseEntities())
     {
         this.listBox1.Items.Clear();
         foreach (Material m in en.Materials)
         {
             this.listBox1.Items.Add(m.Name);
         }
     }
 }
Beispiel #4
0
 public static List <Material> GetAllMaterials()
 {
     try
     {
         using (WareHouseEntities en = new WareHouseEntities())
         {
             return(en.Materials.ToList());
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(new List <Material>());
     }
 }
Beispiel #5
0
 public static bool AddInOut(InOut inOut)
 {
     try
     {
         using (WareHouseEntities en = new WareHouseEntities())
         {
             en.InOuts.Add(inOut);
             en.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }
Beispiel #6
0
 public static bool DeleteInOut(InOut InOut)
 {
     try
     {
         using (WareHouseEntities en = new WareHouseEntities())
         {
             InOut inOut = en.InOuts.First(x => x.ID == InOut.ID);
             en.InOuts.Remove(inOut);
             en.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }
Beispiel #7
0
 public static InOut GetInOutByVOut(VOut vOut)
 {
     try
     {
         using (WareHouseEntities en = new WareHouseEntities())
         {
             return(en.InOuts.Include(p => p.Material).First(x =>
                                                             !x.IsIn &&
                                                             x.Material.Name == vOut.Name &&
                                                             x.Quantity == vOut.Quantity &&
                                                             x.Date == vOut.Date));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(null);
     }
 }
Beispiel #8
0
        private void ViewAll()
        {
            using (WareHouseEntities en = new WareHouseEntities())
            {
                this.lstVIns          = new BindingList <VIn>(en.VIns.ToList());
                this.dgvIn.DataSource = this.lstVIns;

                this.lstVOuts          = new BindingList <VOut>(en.VOuts.ToList());
                this.dgvOut.DataSource = this.lstVOuts;
            }
            this.dgvIn.Columns[0].HeaderText  = "配件名称";
            this.dgvIn.Columns[1].HeaderText  = "价格";
            this.dgvIn.Columns[2].HeaderText  = "数量";
            this.dgvIn.Columns[3].HeaderText  = "时间";
            this.dgvOut.Columns[0].HeaderText = "配件名称";
            this.dgvOut.Columns[1].HeaderText = "价格";
            this.dgvOut.Columns[2].HeaderText = "数量";
            this.dgvOut.Columns[3].HeaderText = "时间";
        }
Beispiel #9
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         this.btnAdd.Enabled = false;
         using (WareHouseEntities en = new WareHouseEntities())
         {
             Material m = new Material();
             m.Name  = this.txtName.Text.Trim();
             m.Price = this.numPrice.Value;
             en.Materials.Add(m);
             en.SaveChanges();
         }
         this.DisplayAllMaterials();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #10
0
 public static bool EditInOut(int oldInOutID, InOut newInOut)
 {
     try
     {
         using (WareHouseEntities en = new WareHouseEntities())
         {
             InOut inOut = en.InOuts.First(x => x.ID == oldInOutID);
             inOut.MID      = newInOut.MID;
             inOut.Quantity = newInOut.Quantity;
             inOut.Date     = newInOut.Date;
             en.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }