Ejemplo n.º 1
0
 private void ImportOrder_Click(object sender, EventArgs e)
 {
     try
     {
         using (var db = new OrderDB())
         {
             OrderService   os             = new OrderService();
             XmlSerializer  xml            = new XmlSerializer(typeof(List <OrderList>));
             OpenFileDialog openFileDialog = new OpenFileDialog();
             openFileDialog.Title           = "Open the file";
             openFileDialog.Filter          = "txt files(*.txt)|*.txt|All files(*.*)|*.*";
             openFileDialog.AddExtension    = true;
             openFileDialog.CheckFileExists = true;
             openFileDialog.CheckPathExists = true;
             openFileDialog.DefaultExt      = "*.txt|*.txt";
             if (openFileDialog.ShowDialog() == DialogResult.OK)
             {
                 FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open);
                 //os.ListOfOrder = (List<Order>)xml.Deserialize(fs);
                 foreach (OrderList order in (List <OrderList>)xml.Deserialize(fs))
                 {
                     os.Add(order);
                 }
                 fs.Close();
                 IQueryable <OrderList> orders = from t in db.Order select t;
                 var list = orders.ToList();
                 b.DataSource = new BindingList <OrderList>(list);
                 OrderbindingSource.DataSource = b;
             }
         }
     }catch (Exception)
     {
         return;
     }
 }
Ejemplo n.º 2
0
 public List <OrderList> QueryByClientName(string name)
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("ListOfDetails")
                .Where(o => o.ClientName.Equals(name)).ToList());
     }
 }
Ejemplo n.º 3
0
 public List <OrderList> QueryByOrderId(string id)
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("ListOfDetails")
                .Where(o => o.OrderId.Equals(id)).ToList());
     }
 }
Ejemplo n.º 4
0
 public OrderList GetOrder(string Id)
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("ListOfDetails").
                SingleOrDefault(o => o.OrderId == Id));
     }
 }
Ejemplo n.º 5
0
 public void Add(OrderList order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Add(order);
         db.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public List <OrderList> QueryByTotalPriceOver(long num)
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("ListOfDetails")
                .Where(o => o.TotalPrice >= num).ToList());
     }
 }
Ejemplo n.º 7
0
 public List <OrderList> QueryByProductName(string name)
 {
     using (var db = new OrderDB())
     {
         var query = db.Order.Include("ListOfDetails")
                     .Where(o => o.ListOfDetails.Where(
                                detail => detail.ProductName.Equals(name)).Count() > 0);
         return(query.ToList());
     }
 }
Ejemplo n.º 8
0
 public void Update(OrderList order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         order.ListOfDetails.ForEach(detail => db.Entry(detail).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public void Delete(string orderId)
 {
     using (var db = new OrderDB())
     {
         var order = db.Order.Include("ListOfDetails").SingleOrDefault(o => o.OrderId == orderId);
         //db.DetailsList.RemoveRange(order.ListOfDetails);
         db.Order.Remove(order);
         db.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public void Export(string xmlFileName)
 {
     using (var db = new OrderDB())
     {
         XmlSerializer xmlser = new XmlSerializer(typeof(List <OrderList>));
         FileStream    fs     = new FileStream(xmlFileName, FileMode.OpenOrCreate);
         xmlser.Serialize(fs, db.Order);
         fs.Close();
     }
 }
Ejemplo n.º 11
0
 private void MenuTool3_Click(object sender, EventArgs e)
 {
     //显示所有订单
     using (var db = new OrderDB())
     {
         IQueryable <OrderList> orders = from t in db.Order select t;
         var list = orders.ToList();
         b.DataSource             = new BindingList <OrderList>(list);
         OrderGridView.DataSource = b;
     }
 }
Ejemplo n.º 12
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var db = new OrderDB())
            {
                List <OrderList>       list   = new List <OrderList>();
                OrderService           os     = new OrderService();
                IQueryable <OrderList> orders = from t in db.Order select t;
                list         = orders.ToList();
                b.DataSource = new BindingList <OrderList>(list);
                if (textBox1.Text != "")
                {
                    string s = textBox1.Text;
                    if (comboBox2.Text == "订单号")
                    {
                        list = os.QueryByOrderId(textBox1.Text);
                    }
                    else if (comboBox2.Text == "用户名")
                    {
                        list = os.QueryByClientName(textBox1.Text);
                    }
                    else if (comboBox2.Text == "总价高于所输入值的")
                    {
                        list = os.QueryByTotalPriceOver(long.Parse(textBox1.Text));
                    }
                    else
                    {
                        list = os.QueryByProductName(textBox1.Text);
                    }

                    if (comboBox1.Text == "查询订单")
                    {
                        if (CheckListNull(list) == true)
                        {
                            OrderbindingSource.DataSource = list;
                        }
                    }
                    else
                    {
                        if (CheckListNull(list) == true)
                        {
                            foreach (OrderList o in list)
                            {
                                os.Delete(o.OrderId);
                            }
                            orders = from t in db.Order select t;
                            list   = orders.ToList();
                            OrderbindingSource.DataSource = b;
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private void ExportOrder_Click(object sender, EventArgs e)
        {
            try
            {
                using (var db = new OrderDB())
                {
                    XmlSerializer  xmlser         = new XmlSerializer(typeof(List <OrderList>));
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Title           = "Save the File";
                    saveFileDialog.Filter          = "txt file(*.txt)|*.txt|html file(*.html)|*.html";
                    saveFileDialog.AddExtension    = true;
                    saveFileDialog.CheckPathExists = true;
                    saveFileDialog.OverwritePrompt = true;
                    saveFileDialog.DefaultExt      = "*.txt|*.txt";
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        //不论结果需要txt还是html,事先生成一个xml文件(txt)
                        string filepath = saveFileDialog.FileName;
                        filepath = Path.GetDirectoryName(filepath);
                        string filename = Path.GetFileNameWithoutExtension(saveFileDialog.FileName);

                        FileStream fs = new FileStream(filepath + filename + ".txt", FileMode.OpenOrCreate);
                        xmlser.Serialize(fs, db.Order);
                        fs.Close();
                        if (saveFileDialog.FilterIndex == 2)
                        {
                            XmlDocument xmlDocument = new XmlDocument();
                            xmlDocument.Load(filepath + filename + ".txt");

                            XPathNavigator navigator = xmlDocument.CreateNavigator();
                            navigator.MoveToRoot();

                            XslCompiledTransform xslCompiledTransform = new XslCompiledTransform();
                            xslCompiledTransform.Load(@"..\..\OrderList.xslt");

                            FileStream        fileStream = File.OpenWrite(saveFileDialog.FileName);
                            XmlWriterSettings settings   = new XmlWriterSettings();
                            XmlWriter         xmlWriter  = XmlWriter.Create(fileStream, settings);

                            xslCompiledTransform.Transform(navigator, null, xmlWriter);
                            File.Delete(filepath + filename + ".txt");
                            fileStream.Close();
                        }
                    }
                }
            }catch (Exception)
            {
                MessageBox.Show("您所输入的订单有误!", "输入错误!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
Ejemplo n.º 14
0
 private bool CheckListNull(List <OrderList> list)
 {
     if (list == null)
     {
         using (var db = new OrderDB())
         {
             MessageBox.Show("未找到相关订单。", "输入错误!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             textBox1.Text = null;
             OrderbindingSource.DataSource = db.Order;
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 15
0
 // 序列化
 public void Import(string xmlFileName)
 {
     using (var db = new OrderDB())
     {
         XmlSerializer xmlser = new XmlSerializer(typeof(List <OrderList>));
         FileStream    fs     = new FileStream(xmlFileName, FileMode.Open);
         //db.OrderList = (List<Order>)xmlser.Deserialize(fs);
         foreach (OrderList order in (List <OrderList>)xmlser.Deserialize(fs))
         {
             Add(order);
         }
         fs.Close();
     }
 }
Ejemplo n.º 16
0
 private void MenuTool1_Click(object sender, EventArgs e)
 {
     using (var db = new OrderDB())
     {
         IQueryable <OrderList> order = from t in db.Order select t;
         var          list            = order.ToList();
         AddOrderForm addOrderForm    = new AddOrderForm(list);
         addOrderForm.TransfEvent += AddOrderForm_Add;
         addOrderForm.ShowDialog();
         order        = from t in db.Order select t;
         list         = order.ToList();
         b.DataSource = new BindingList <OrderList>(list);
         OrderbindingSource.DataSource = b;
     }
 }
Ejemplo n.º 17
0
 private void 修改订单ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var db = new OrderDB())
     {
         string          value           = OrderGridView.Rows[OrderGridView.CurrentRow.Index].Cells[0].Value.ToString();
         OrderList       order           = os.QueryByOrderId(value)[0];
         OrderList       o               = os.QueryByOrderId(value)[0];
         ChangeOrderForm changeOrderForm = new ChangeOrderForm(o);
         changeOrderForm.ShowDialog();
         os.Update(o);
         IQueryable <OrderList> orders = from t in db.Order select t;
         var list = orders.ToList();
         b.DataSource = new BindingList <OrderList>(list);
         OrderbindingSource.DataSource = b;
     }
 }
Ejemplo n.º 18
0
        public IEnumerable <Order> QueryOrderbyId(string id)
        {
            using (var db = new OrderDB())
            {
                return(db.Order.Include("Items").
                       SingleOrDefault(o => o.Id == Id));
            }
            var query = orderlist.Where(o => o.OrderId.Equals(id));

            if (query.FirstOrDefault() == null)
            {
                Console.WriteLine("订单号不存在!");
                return(null);
            }
            else
            {
                return(query);
            }
        }
Ejemplo n.º 19
0
 public List <OrderList> GetAllOrders()
 {
     using (var db = new OrderDB())
         return(db.Order.Include("ListOfDetails").ToList());
 }