Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            var data = client.ProductList();

            dataGridView1.DataSource = data;
            client.Close();
        }
Beispiel #2
0
        private void btnProduct_Click(object sender, EventArgs e)
        {
            ProductServiceClient client = new ProductServiceClient();

            dataGridView1.DataSource = client.ProductList();
            client.Close();
        }
Beispiel #3
0
        private void UpdateProduct(Guid productId)
        {
            // Show product info
            var productServiceClient = new ProductServiceClient();

            try {
                _productContract =
                    productServiceClient.ProductGetCompleteById(
                        productId);

                if (productId == Guid.Empty)
                {
                    // todo
                    // either set this to empty here, or allow comobo / datetime, etc to be null/empty
                    // note 1.. not doing this now because it causes flicker in the end
                    //textBoxProductName.Text = string.Empty;
                    //stateRefComboProduct.Text = string.Empty;
                    //dateTimePickerProduct.Text = string.Empty;
                }
                else
                {
                    textBoxProductName.Text = _productContract.Product.ProductName;

                    PopulateProductAttribute(_productContract.ProductAttribute);
                    PopulateProductIdentifier(_productContract.ProductIdentifier);
                    PopulateProductInfo(_productContract.ProductInfo);
                    PopulateProductImage(_productContract.ProductImage);
                    PopulateProductDocument(_productContract.ProductDocumentation);
                }
            } catch (Exception ex) {
                Error(ex);
            } finally {
                productServiceClient.Close();
            }
        }
Beispiel #4
0
 public Product()
 {
     using (ProductServiceClient client = new ProductServiceClient())
     {
         Proxy = client.CreateProduct();
         client.Close();
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            HelloWorldServiceClient client = new HelloWorldServiceClient();

            Console.WriteLine(client.Greet(new Person {
                Name = "Roger"
            }));
            client.Close();

            ProductServiceClient client2 = new ProductServiceClient();

            Console.WriteLine(client2.GetPrice(new Product {
                Name = "potato", Price = 0.55
            }));
            client2.Close();
            Console.ReadLine();
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            ProductServiceClient productHistory = new ProductServiceClient();
            BindingSource        bindingSource  = new BindingSource();

            try {
                bindingSource.DataSource = productHistory.ProductHistory(_productId);
                grid.AutoGenerateColumns = true;
                grid.DataSource          = bindingSource;
                grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                grid.AutoResizeColumns();
                grid.Refresh();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            } finally {
                productHistory.Close();
            }
        }
        private void PopulateProductHistory()
        {
            Log("PopulateProductHistory");

            ProductServiceClient productHistory = new ProductServiceClient();
            BindingSource        bindingSource  = new BindingSource();

            try {
                bindingSource.DataSource = productHistory.ProductHistory(_productContract.Product.ProductId);
                dataGridViewProductHistory.AutoGenerateColumns = true;
                dataGridViewProductHistory.DataSource          = bindingSource;
                dataGridViewProductHistory.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                dataGridViewProductHistory.AutoResizeColumns();
                dataGridViewProductHistory.Refresh();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            } finally {
                productHistory.Close();
            }
        }
Beispiel #8
0
        /// <summary>
        /// 提交商品数据
        /// </summary>
        /// <returns></returns>
        public JsonResult AjaxAddGoods()
        {
            string     userToken = CurrentToken;
            string     goods     = Request["goods"];
            string     del_items = Request["del_items"] ?? "";
            RespResult response  = new RespResult();

            if (string.IsNullOrEmpty(goods))
            {
                response.Error        = DataStructure.AppError.ERROR_INVALID_PARAMETER;
                response.ErrorMessage = "数据丢失!";
            }
            else
            {
                try
                {
                    ProductModel product = JsonHelper.Deserialize <ProductModel>(goods);
                    product.QQ    = product.QQ == "QQ" ? string.Empty : product.QQ;
                    product.Phone = product.Phone == "手机号" ? string.Empty : product.Phone;
                    if (!string.IsNullOrEmpty(CurrentToken))
                    {
                        userToken = CurrentToken;
                    }
                    //未登录的情况(先注册)
                    else
                    {
                        string            username   = string.IsNullOrEmpty(product.Phone) || product.Phone == "手机号" ? product.QQ : product.Phone;
                        UserServiceClient userclient = new UserServiceClient();
                        try
                        {
                            response = userclient.Register(username, SecurityHelper.MD5("000000"));
                            if (response.Error == AppError.ERROR_SUCCESS)
                            {
                                AdvancedResult <string> regLogin = userclient.Login(username, SecurityHelper.MD5("000000"));
                                userToken = regLogin.Data;
                            }
                        }
                        finally
                        {
                            userclient.Close();
                            userclient = null;
                        }
                    }

                    ProductServiceClient client = new ProductServiceClient();

                    if (product == null)
                    {
                        response.Error        = DataStructure.AppError.ERROR_INVALID_PARAMETER;
                        response.ErrorMessage = "无效数据!";
                    }
                    else
                    {
                        AdvancedResult <int> productResponse;
                        if (product.Id > 0)
                        {
                            RespResult result = client.EditBBPostInfo(product.Id, product.Title, product.QQ, product.Phone, product.Description, product.IsWash, product.Price, product.Age, product.ItemType, product.ItemSort, product.Sex, userToken);
                            productResponse              = new AdvancedResult <int>();
                            productResponse.Data         = product.Id;
                            productResponse.Error        = result.Error;
                            productResponse.ErrorMessage = result.ErrorMessage;
                            productResponse.ExMessage    = result.ExMessage;
                        }
                        else
                        {
                            productResponse = client.publishBBPost(product.Title, product.QQ, product.Phone, product.Description, product.IsWash, product.Price, product.Age, product.ItemType, product.ItemSort, product.Sex, userToken);
                        }

                        if (productResponse.Error == DataStructure.AppError.ERROR_SUCCESS)
                        {
                            foreach (var pitem in product.Pics)
                            {
                                //if (pitem.Pid > 0)
                                //{
                                //    client.EditeBBPic(pitem.Pid, pitem.PicId, CurrentToken);
                                //}
                                //else
                                //{
                                client.BindBBPic(productResponse.Data, pitem.PicId, userToken);
                                //}
                            }
                        }
                        response.ErrorMessage = productResponse.ErrorMessage;
                        response.ExMessage    = productResponse.ExMessage;
                        response.Error        = productResponse.Error;
                    }
                    int[] delItemsList = del_items.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(a => Convert.ToInt32(a)).Where(a => a > 0).ToArray();
                    foreach (int itemId in delItemsList)
                    {
                        client.DeleteBBPic(itemId, userToken);
                    }
                    client.Close();
                    client = null;
                }
                catch (Exception ex)
                {
                    response.ExMessage = "保存失败!" + ex.Message;
                    response.Error     = DataStructure.AppError.ERROR_FAILED;
                }
            }
            return(Json(response));
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            ProductServiceClient client = new ProductServiceClient();

            printWelcome();
            printOptions();
            int op = getIntegerFromUserInput();

            while (op != -1)
            {
                if (op == 1)
                {
                    List <OrderDTO> orders = client.getOrders().ToList();
                    pl("Orders already done:");
                    pl("OrderID, ClientID, ProductID, Quantity, Date, ShipperID");
                    pl("-------------------------------------------------------");
                    foreach (OrderDTO o in orders)
                    {
                        pl(o.OrderID + ", " + o.ClientID + ", " + o.ProductID + ", " + o.Quantity + ", " + o.Date.ToShortDateString() + ", " + o.ShipperID);
                    }
                }
                else if (op == 2)
                {
                    List <PendingOrderDTO> orders = client.getPendingOrders().ToList();
                    pl("Orders pending to be accepted:");
                    pl("OrderID, ClientID, ProductID, Quantity, Date, ShipperID");
                    pl("-------------------------------------------------------");
                    foreach (PendingOrderDTO o in orders)
                    {
                        pl(o.OrderID + ", " + o.ClientID + ", " + o.ProductID + ", " + o.Quantity + ", " + o.Date.ToShortDateString() + ", " + o.ShipperID);
                    }
                }
                else if (op == 3)
                {
                    p("Client identifier > ");
                    int clientId = getIntegerFromUserInput();
                    p("Product identifier > ");
                    int productId = getIntegerFromUserInput();
                    p("Quantity of the product > ");
                    int quantity = getIntegerFromUserInput();
                    p("Date (dd/mm/yyyy) > ");
                    String date = getStringFromUserInput();
                    p("Shipper identifier > ");
                    int shipperId = getIntegerFromUserInput();
                    int orderId   =
                        client.requestOrder(clientId, productId, quantity, date, shipperId);
                    if (orderId > 0)
                    {
                        pl("Order has been requested, the following identifies has been generated: " + orderId);
                    }
                    else
                    {
                        pl("Some error happened and the request could not be registered.");
                    }
                }
                else if (op == 4)
                {
                    List <ClientDTO> clients = client.getClients().ToList();
                    pl("Clients in database:");
                    pl("Identifier, Name, City, Prefered format");
                    pl("-------------------------------------");
                    foreach (ClientDTO c in clients)
                    {
                        pl(c.ClientID + ", " + c.Name + ", " + c.City + ", " + c.PreferedFormat);
                    }
                }
                else if (op == 5)
                {
                    List <ProductDTO> products = client.getProducts().ToList();
                    pl("Products in database:");
                    pl("Identifier, Name, Type, Local stock, Price, Cost");
                    pl("------------------------------------------------");
                    foreach (ProductDTO p in products)
                    {
                        pl(p.ProductID + ", " + p.ProductName + ", " + p.Type + ", " + p.Quantity + ", " + p.Price + ", " + p.Cost);
                    }
                }
                else if (op == 6)
                {
                    List <ShipperDTO> shippers = client.getShippers().ToList();
                    pl("Shippers in database:");
                    pl("Identifier, Name, City, Cost per ton");
                    pl("------------------------------------");
                    foreach (ShipperDTO s in shippers)
                    {
                        pl(s.ShipperID + ", " + s.Name + ", " + s.City + ", " + s.CostPerTon);
                    }
                }
                else if (op == -1)
                {
                    client.Close();
                    return;
                }
                else
                {
                    pl("Please input a valid option.");
                }
                pl(" ");
                printOptions();
                op = getIntegerFromUserInput();
            }
        }