Exemple #1
0
        public static List <Order> Import()
        {
            List <Order> orders   = new List <Order>();
            XDocument    document = XDocument.Load("Orders.xml");
            XElement     root     = document.Root;

            for (int i = 0; root.Element("Order" + (i)) != null; i++)
            {
                XElement            order  = root.Element("Order" + i);
                List <OrderedCargo> cargos = new List <OrderedCargo>();
                XElement            Cargos = order.Element("Cargos");
                for (int j = 0; Cargos.Element("cargo" + (j)) != null; j++)
                {
                    XElement     cargo       = Cargos.Element("cargo" + (j));
                    string       str         = cargo.Value;
                    string[]     strs        = str.Split(' ');
                    OrderedCargo singleCargo = new OrderedCargo(strs[0], double.Parse(strs[1]), Int32.Parse(strs[2]));
                    cargos.Add(singleCargo);
                }
                XElement client = order.Element("Client");
                XElement remark = order.Element("Remark");

                Detail detail      = new Detail(cargos, client.Value, remark.Value);
                Order  singleOrder = new Order(i, detail);
                orders.Add(singleOrder);
            }

            return(orders);
        }
Exemple #2
0
        private void btnAddcargo_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < cargoGrid.RowCount - 1; i++)
            {
                if (txtC.Text == cargoGrid.Rows[i].Cells[0].Value.ToString())
                {
                    cargoGrid.Rows[i].Cells[2].Value = Int32.Parse(cargoGrid.Rows[i].Cells[2].Value.ToString()) + Int32.Parse(txtNum.Text);
                    return;
                }
            }
            cargoGrid.Rows.Add();
            cargoGrid.Rows[cargoGrid.Rows.Count - 2].Cells[0].Value = txtC.Text;
            cargoGrid.Rows[cargoGrid.Rows.Count - 2].Cells[1].Value = txtPrice.Text;
            cargoGrid.Rows[cargoGrid.Rows.Count - 2].Cells[2].Value = txtNum.Text;
            OrderedCargo cargo = new OrderedCargo(txtC.Text, double.Parse(txtPrice.Text), Int32.Parse(txtNum.Text));

            cargos.Add(cargo);
        }
Exemple #3
0
        public static void Update(Order order)
        {
            try
            {
                bool cyc = true;
                while (cyc)
                {
                    Console.WriteLine("1、修改顾客,2、添加商品,3、减少商品,4、修改备注,5、退出");
                    Console.WriteLine("输入选择:");
                    string str = Console.ReadLine();
                    switch (str)
                    {
                    case "1":
                    {
                        Console.WriteLine("输入新顾客信息:");
                        string client = Console.ReadLine();
                        order.detail.Client = client;
                        break;
                    }

                    case "2":
                    {
                        int tept = -1;
                        Console.WriteLine("需要添加的商品:");
                        string cargoname = Console.ReadLine();
                        for (int i = 0; i < order.detail.Cargos.Count; i++)
                        {
                            if (order.detail.Cargos[i].Name == cargoname)
                            {
                                tept = i;
                            }
                        }
                        try
                        {
                            if (tept == -1)
                            {
                                Console.WriteLine("单价:");
                                double price = double.Parse(Console.ReadLine());
                                Console.WriteLine("个数:");
                                int          num          = Int32.Parse(Console.ReadLine());
                                OrderedCargo orderedCargo = new OrderedCargo(cargoname, price, num);
                                order.detail.Cargos.Add(orderedCargo);
                                order.detail.Price += orderedCargo.Price * orderedCargo.Num;
                            }
                            else
                            {
                                Console.WriteLine("添加个数:");
                                int num = Int32.Parse(Console.ReadLine());
                                order.detail.Cargos[tept].Num += num;
                                order.detail.Price            += num * order.detail.Cargos[tept].Price;
                            }
                            break;
                        }catch (Exception e)
                        {
                            throw new Exception("输入格式不正确");
                        }
                    }

                    case "3":
                    {
                        int tept = -1;
                        Console.WriteLine("需要删除的商品:");
                        string cargoname = Console.ReadLine();
                        for (int i = 0; i < order.detail.Cargos.Count; i++)
                        {
                            if (order.detail.Cargos[i].Name == cargoname)
                            {
                                tept = i;
                            }
                        }
                        try
                        {
                            if (tept == -1)
                            {
                                Console.WriteLine("无该商品");
                            }
                            else
                            {
                                Console.WriteLine("减少个数:");
                                int num = Int32.Parse(Console.ReadLine());
                                if (num > order.detail.Cargos[tept].Num)
                                {
                                    Console.WriteLine("没有这么多该商品");
                                }
                                else if (num == order.detail.Cargos[tept].Num)
                                {
                                    order.detail.Cargos.RemoveAt(tept);
                                    order.detail.getPrice();
                                }
                                else
                                {
                                    order.detail.Cargos[tept].Num -= num;
                                    order.detail.getPrice();
                                    //order.detail.Price -= num * order.detail.Cargos[tept].Price;
                                }
                            }
                            break;
                        }
                        catch (Exception e)
                        {
                            throw new Exception("输入格式不正确");
                        }
                    }

                    case "4":
                    {
                        Console.WriteLine("输入新备注信息:");
                        string remark = Console.ReadLine();
                        order.detail.remark = remark;
                        break;
                    }

                    case "5": cyc = false; break;

                    default: break;
                    }
                }
            }
            catch
            {
                throw new Exception("输入格式不正确");
            }
        }