예제 #1
0
파일: MainForm.cs 프로젝트: kkcn-git/Egode
        void odc_OnAddPacket(object sender, PacketInfo p)
        {
            try
            {
                string orderDetailsHtml = GetOrderDetailsHtml(p.OrderId);
                if (orderDetailsHtml.ToLower().Contains("退款信息"))
                {
                    MessageBox.Show(this, "此订单已申请退款. 终止发货!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (!orderDetailsHtml.Contains("买家已付款,等待卖家发货"))
                {
                    DialogResult dr = MessageBox.Show(this, "此订单不是<买家已付款, 等待卖家发货>状态, 是否继续发货操作?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                    if (DialogResult.No == dr)
                    {
                        return;
                    }
                }

                string       warning;
                List <Order> buyerOrders;
                if (IsMultipleOrders(Order.GetOrderByOrderId(p.OrderId, _orders).BuyerAccount, _orders, out buyerOrders, out warning))
                {
                    OrdersForm of = new OrdersForm(buyerOrders);
                    of.Prompt = string.Format("注意! 此账号有多个订单. {0}. 是否继续出单?", warning);
                    DialogResult dr = of.ShowDialog(this);
                    if (DialogResult.Cancel == dr)
                    {
                        return;
                    }
                }

                //if (IsMultipleOrders(Order.GetOrderByOrderId(p.OrderId, _orders).BuyerAccount, _orders, out warning))
                //{
                //    DialogResult dr = MessageBox.Show(
                //        this,
                //        string.Format("注意!!! 此账号有多个订单:\n{0}\n\n是否继续出单?", warning), this.Text,
                //        MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                //    if (DialogResult.No == dr)
                //        return;
                //}

                if (null == _packets)
                {
                    _packets = new List <PacketInfo>();
                }

                _packets.Add(p);
                tsbtnGeneratePackets.Enabled = (_packets.Count > 0);
                tsslblInfo.Text = string.Format("{0} packets added.", _packets.Count);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
예제 #2
0
        public PacketInfo Clone()
        {
            PacketInfo pi = new PacketInfo(_orderId, base.Type, base.Weight, base.Price, _fullAddress, _phoneNumber, _homePhoneNumber, _productInfo);

            pi._recipientNameCn = _recipientNameCn;
            pi._recipientNameEn = _recipientNameEn;
            pi._provinceCityCn  = _provinceCityCn;
            pi._provinceCityEn  = _provinceCityEn;
            pi._addressCn       = _addressCn;
            pi._addressEn       = _addressEn;
            pi._postCode        = _postCode;

            return(pi);
        }
예제 #3
0
        // 创建1个packet info在包裹单申请表中对应的值列表, 用于插入excel表格.
        private object[] CreatePacketInfoSupermarketValues(int index, PacketInfo pi)
        {
            if (null == pi)
            {
                return(null);
            }

            //string sql = "Insert into [Sheet1$] values(1,'realkk','000','','','','','','','','*****@*****.**','Hu Jun','Otto Brenner Str.','4a','47877','Willich','Deutschland','21177920614','Zhang GuoQiang','China','330000','JiangXiShengNanChangShi','HongGuTangDaShaAZuo13Lou',' ',' ','138000000000','Gift',6,50,'张国亮','江西省南昌市','红谷滩大厦A做13楼','330000','13800000000')";
            return(new object[] {
                index, "realkk", "000",
                "", "", "", "", "", "", "",
                "*****@*****.**", "Hu Jun", "Otto Brenner Str.", "4a", "47877", "Willich", "Deutschland", "21177920614",
                pi.RecipientNameEn, "China", pi.PostCode, pi.ProvinceCityEn.Replace(" ", string.Empty), pi.AddressEn,
                " ", " ",
                pi.PhoneNumber,
                "Gift", (pi.Weight / 1000).ToString("0"), 50,
                pi.RecipientNameCn, pi.ProvinceCityCn, pi.AddressCn, pi.PostCode, pi.PhoneNumber
            });
        }
예제 #4
0
        private void btnAddPacket_Click(object sender, EventArgs e)
        {
            if (null != this.OnAddPacket)
            {
                // 提醒
                if (_order.LocalPrepared)
                {
                    DialogResult dr = MessageBox.Show(
                        this.FindForm(),
                        "此订单已添加包裹单.\n是否要为此订单生成多个包裹单?", this.FindForm().Text,
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (DialogResult.No == dr)
                    {
                        return;
                    }
                }

                // Have not get full edited address yet
                if (!string.IsNullOrEmpty(_order.EditedRecipientAddress.Trim()) && txtEditedAddress.Text.Equals(_order.EditedRecipientAddress.Trim()))
                {
                    MessageBox.Show(
                        this.FindForm(),
                        "收货地址发生修改.\n导出数据无法获得完整修改后的地址, 需要访问订单详情页面获得完整地址.",
                        this.FindForm().Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    btnGetFullEditedAddress_Click(btnGetFullEditedAddress, EventArgs.Empty);
                }

                Packet     p           = (Packet)cboPackets.SelectedItem;
                string     fullAddress = !string.IsNullOrEmpty(txtEditedAddress.Text) ? txtEditedAddress.Text : txtAddress.Text;
                string     phoneNumber = string.IsNullOrEmpty(_order.MobileNumber) ? _order.PhoneNumber : _order.MobileNumber;
                PacketInfo pi          = new PacketInfo(_order.OrderId, p.Type, p.Weight, p.Price, fullAddress, phoneNumber, _order.PhoneNumber, _order.Items);
                this.OnAddPacket(this, pi);
                _order.LocalPrepare();
            }
        }
예제 #5
0
        public PacketDetailsControl(PacketInfo pi, int index)
        {
            _packetInfo = pi;
            InitializeComponent();
            lblIndex.Text = index.ToString();

            txtBuyerRemark.Text    = pi.BuyerRemark;
            pnlBuyerRemark.Visible = !string.IsNullOrEmpty(pi.BuyerRemark);
            txtRemark.Text         = pi.Remark;
            pnlRemark.Visible      = !string.IsNullOrEmpty(pi.Remark);

            // Generate description for products.
            #region obsoleted code

            /*
             * StringBuilder sbProducts = new StringBuilder();
             * string[] itemInfos = _packetInfo.ProductInfo.Split('★');
             * for (int i = 0; i < itemInfos.Length; i++)
             * {
             *      string itemInfo = itemInfos[i];
             *      string[] infos = itemInfo.Split('☆');
             *      if (infos.Length < 3)
             *              continue;
             *
             *      bool cancelled = false;
             *      bool sent = false;
             *      if (infos.Length >= 4)
             *      {
             *              cancelled = (((Order.OrderStatus)Enum.Parse(typeof(Order.OrderStatus), infos[3])) == Order.OrderStatus.Closed);
             *              sent = (((Order.OrderStatus)Enum.Parse(typeof(Order.OrderStatus), infos[3])) == Order.OrderStatus.Sent);
             *      }
             *      if (cancelled || sent)
             *              continue;
             *
             *      if (infos[0].Contains("加强包装费"))
             *              continue;
             *      if (infos[0].Contains("气囊加固"))
             *              continue;
             *
             *      ProductInfo productInfo = ProductInfo.Match(infos[0]);
             *      string productTitle = string.Empty;
             *      if (null != productInfo)
             *      {
             *              productTitle = productInfo.ShortName;
             *              nudNetWeight.Value += (decimal)(productInfo.Weight * int.Parse(infos[2]) / 1000);
             *      }
             *      else
             *      {
             *              productTitle = Order.SimplifyItemSubject(infos[0], true).Trim();
             *      }
             *
             *      sbProducts.Append(string.Format("{0}; {1}\r\n", productTitle, infos[2])); // [0]:title, [1]:amount.
             * }
             */
            #endregion

            StringBuilder sbProducts = new StringBuilder();
            foreach (SoldProductInfo spi in _packetInfo.Products)
            {
                if (spi.Status == Order.OrderStatus.Sent || spi.Status == Order.OrderStatus.Closed)
                {
                    continue;
                }
                sbProducts.Append(string.Format("{0}; {1}\r\n", spi.ShortName, spi.Count));                 // [0]:title, [1]:amount.
                nudNetWeight.Value += (decimal)(spi.Weight * spi.Count / 1000);
            }

            if (sbProducts.Length > 2 && sbProducts.ToString().EndsWith("\r\n"))
            {
                sbProducts.Remove(sbProducts.Length - 2, 2);               // remove return at the end of string.
            }
            txtProduct.Text   = sbProducts.ToString();
            txtProduct.Height = txtProduct.PreferredSize.Height;

            cboPackets.Items.Add(new Packet(PacketTypes.Unknown, 0, 0));

            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 5000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 5500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 6000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 6500, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 5000, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 6000, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 7000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 7500, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 8000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 8500, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 9000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 9500, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 10000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 10500, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 11000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 11500, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 12000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 12500, 0));
            cboPackets.Items.Add(new Packet(PacketTypes.Time24_PostNL, 13000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.PostNL, 14000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.PostNL, 15000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.PostNL, 20000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.PostNL, 25000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.PostNL, 30000, 0));

            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 5000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 5500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 6000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 6500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 7000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 7500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 8000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 8500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 9000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 9500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 10000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 10500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 11000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 11500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 12000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 12500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 13000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 13500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 14000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 14500, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 15000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 20000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 25000, 0));
            //cboPackets.Items.Add(new Packet(PacketTypes.Hanslord, 31500, 0));

            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 5000, 239));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 5500, 245));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 6000, 250));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 6500, 255));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 7000, 260));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 7500, 265));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 8000, 270));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 8500, 275));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 9000, 290));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 9500, 295));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 10000, 300));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 10500, 310));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 11000, 323));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 11500, 333));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 12000, 343));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 12500, 353));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 13000, 363));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 14000, 373));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 15000, 393));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 20000, 483));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 25000, 573));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 30000, 663));

            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 6000, 265));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 8000, 275));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 9000, 285));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 10000, 300));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 11000, 310));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 12000, 320));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 13000, 330));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 14000, 340));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 15000, 375));
            //cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 20000, 420));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 7000, 241));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 8000, 258));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 9000, 285));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 15000, 358));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 5000, 246));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 5500, 251));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 6000, 258));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 6500, 263));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 7000, 268));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 7500, 273));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 8000, 278));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 8500, 288));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 9000, 298));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 9500, 303));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 10000, 308));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 10500, 320));

            for (int i = 0; i < cboPackets.Items.Count; i++)
            {
                Packet p = (Packet)cboPackets.Items[i];
                if (p.Type == _packetInfo.Type && p.Weight == _packetInfo.Weight)
                {
                    cboPackets.SelectedIndex = i;
                    break;
                }
            }

            // fill full original address.
            txtFullAddress.Text = _packetInfo.FullAddress;

            // Modified by KK on 2013/09/25.
            // 对于修改过地址的订单, 下述代码取到的是老地址的电话号码.
            //txtPhoneNumber.Text = _packetInfo.PhoneNumber;
            // 如果么有修改过地址, FullAddress就是根据老地址生成; 如果修改过, 就是根据新地址生成. 因此从FullAddress中取到的电话号码总是正确的.
            txtPhoneNumber.Text = (_packetInfo.FullAddress.Contains(",")? _packetInfo.FullAddress.Replace(",", ","):_packetInfo.FullAddress).Split(',')[1].Trim(); // Assert!!!

            try                                                                                                                                                    // If error occurs let operator edit address itself.
            {
                // Get post code.
                string postCode = string.Empty;
                Regex  regex    = new Regex(@"(\(\d{6}\))|(,\d{6}$)");
                Match  m        = regex.Match(_packetInfo.FullAddress.Replace(",", ","));
                //Trace.Assert(m.Success);
                if (m.Success)
                {
                    postCode         = m.Value;
                    postCode         = postCode.Replace("(", string.Empty).Replace(")", string.Empty).Replace(",", string.Empty);
                    txtPostCode.Text = postCode;
                }

                // Analyse address. Get information for original address.
                string[] recipientInfos = _packetInfo.FullAddress.Replace(",", ",").Replace(m.Value, string.Empty).Trim().Split(',');
                txtRecipientName.Text = recipientInfos[0].Trim();

                // Get address details.
                string[] addressInfos = recipientInfos[recipientInfos.Length - 1].Split(' ');
                string   province     = string.Empty;
                string   city1        = string.Empty;
                string   city2        = string.Empty;
                foreach (string s in addressInfos)
                {
                    string ss = s.Trim();

                    if (ss.EndsWith("省") || ss.EndsWith("自治区") || ss.Equals("北京") || ss.Equals("上海") || ss.Equals("天津") || ss.Equals("重庆"))
                    {
                        province = ss;
                    }
                    if (ss.EndsWith("市") && !ss.StartsWith(province))
                    {
                        if (string.IsNullOrEmpty(city1))
                        {
                            city1 = ss;
                        }
                        else
                        {
                            city2 = ss;
                        }
                    }
                }
                if (!province.EndsWith("省") && !province.EndsWith("自治区") && !province.EndsWith("市"))                 // 直辖市.
                {
                    province += "市";
                }
                txtProvinceCity.Text = string.Format("{0} {1} {2}", province, city1, city2).Replace("广西壮族自治区", "广西省").Replace("宁夏回族自治区", "宁夏省").Replace("内蒙古自治区", "内蒙古").Replace("西藏自治区", "西藏").Replace("新疆维吾尔自治区", "新疆");

                // Get district;
                string   streetAddress      = RemoveStartingProvinceCity(recipientInfos[recipientInfos.Length - 1], province, city1, city2);
                string[] streetAddressInfos = streetAddress.Split(' ');                 // 此处如果还有空格分隔, 则认为第1个字符串是区. 但是如果买家在街道地址中也输入了空格, 可能出错.
                string   district           = string.Empty;
                if (streetAddressInfos.Length >= 2)
                {
                    district = streetAddressInfos[0];
                }
                if (!string.IsNullOrEmpty(district))
                {
                    streetAddress = streetAddress.Replace(district, string.Empty).Trim();
                }

                // 至此, 得到了去掉了前面的省市区的地址, 也即是买家在淘宝上手动输入的部分.
                // 需要去除买家可能重复输入的省市区信息.
                if (streetAddress.StartsWith(province))                 // remove starting province.
                {
                    streetAddress = streetAddress.Substring(province.Length, streetAddress.Length - province.Length);

                    // 如果是直辖市, 可能会在字符串首留下个"市".
                    if (streetAddress.StartsWith("市"))
                    {
                        streetAddress = streetAddress.Substring(1, streetAddress.Length - 1);
                    }
                }

                if (streetAddress.StartsWith(city1))                 // remove starting city1.
                {
                    streetAddress = streetAddress.Substring(city1.Length, streetAddress.Length - city1.Length);
                }

                if (streetAddress.StartsWith(city2))                 // remove starting city2.
                {
                    streetAddress = streetAddress.Substring(city2.Length, streetAddress.Length - city2.Length);
                }

                if (streetAddress.StartsWith(district))                 // remove starting district.
                {
                    streetAddress = streetAddress.Substring(district.Length, streetAddress.Length - district.Length);
                }

                txtStreetAddress.Text = district + streetAddress.Replace(m.Value, string.Empty);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            // Added by KK on 2016/12/12.
            System.Text.RegularExpressions.Regex r     = new System.Text.RegularExpressions.Regex(@"\d{17}[\d|x|X]");
            System.Text.RegularExpressions.Match match = r.Match(_packetInfo.Remark);
            if (match.Success)
            {
                txtExportInfo.Text = match.Value;
            }

            tblOuter.Height = pnlPinyinAddress.Top + tblPinyinAddress.Height + 2;             // 修正尺寸. 不知道为啥各panel都是autosize最后尺寸还是有误差 -_-|||
            this.Height     = tblOuter.Height;
        }
예제 #6
0
        private string GeneratePackingListExcelFile(List <PacketInfo> packetInfos, string folder)
        {
            // Generate list for JHT.
            string destPackingListJHT = CreateOutputFile(
                Directory.GetParent(Application.ExecutablePath).FullName, PACKING_LIST_TEMPLATE,
                folder, string.Format(PACKING_LIST_OUTPUT_JHT, DateTime.Now.ToString("yyyyMMdd")));

            if (string.IsNullOrEmpty(destPackingListJHT))
            {
                #region error message
                MessageBox.Show(
                    this,
                    "Create excel file for shipping list for JHT failed.\nMaybe the template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                #endregion
                return(string.Empty);
            }

            Excel excelPackingListJHT = new Excel(destPackingListJHT);

            try
            {
                for (int i = 0; i < packetInfos.Count; i++)
                {
                    PacketInfo pi       = packetInfos[i];
                    string[]   products = pi.ProductInfo.Split(new char[] { '\r', '\n' });

                    for (int j = 0; j < products.Length; j++)
                    {
                        if (string.IsNullOrEmpty(products[j].Trim()))
                        {
                            continue;
                        }

                        string[] productDetails = products[j].Split(';');
                        object[] values         = new object[] {
                            j == 0 ? (i + 1).ToString():" ",
                            j == 0 ? pi.RecipientNameCn:" ",
                            j == 0 ? "000000000000":" ",
                            productDetails[0].Trim(), productDetails[1].Trim(),
                            productDetails.Length >= 3 ? productDetails[2].Trim() : string.Empty
                        };

                        excelPackingListJHT.Insert("Sheet1", string.Empty, values);
                    }
                }
            }
            catch (Exception ex)
            {
                #region error message
                MessageBox.Show(
                    this,
                    "Error occured during write data into excel file for packing:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                #endregion
            }
            finally
            {
                excelPackingListJHT.Close();
            }

            return(destPackingListJHT);
        }
예제 #7
0
        private string GenerateOuhuaFiles(List <PacketInfo> packetInfos, string folder)
        {
            try
            {
                string destExcelFile = CreateOutputFile(
                    Directory.GetParent(Application.ExecutablePath).FullName, OUHUA_TEMPLATE_FILENAME,
                    folder,
                    string.Format(OUHUA_EXCEL_OUTPUT_FILENAME, DateTime.Now.ToString("yyyyMMdd")));
                #region error message
                if (string.IsNullOrEmpty(destExcelFile))
                {
                    MessageBox.Show(
                        this,
                        "Create excel file for Ohua failed.\nMaybe rainbow template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(string.Empty);
                }
                #endregion

                Excel excel = new Excel(destExcelFile);

                try
                {
                    string packTitle         = string.Empty;
                    string realkk            = string.Empty;
                    string pingzhangEmail    = string.Empty;
                    string weight            = string.Empty;
                    string JHT               = string.Empty;
                    string OttoBrennerStr    = string.Empty;
                    string str4a             = string.Empty;
                    string PLZ47877          = string.Empty;
                    string OrtWillich        = string.Empty;
                    string TelNr021548839989 = string.Empty;
                    string deutschland       = string.Empty;
                    string recipientName     = string.Empty;
                    string address           = string.Empty;
                    string address2          = string.Empty;
                    string address3          = string.Empty;
                    string postCode          = string.Empty;
                    string provinceCity      = string.Empty;
                    string china             = string.Empty;
                    string phoneNumber       = string.Empty;
                    string fullAddressCn     = string.Empty;
                    string milkPowder        = string.Empty;
                    string count             = string.Empty;
                    string moneyAmount       = string.Empty;

                    for (int i = 0; i < packetInfos.Count; i++)
                    {
                        PacketInfo pi = packetInfos[i];
                        packTitle += string.Format("'包裹单{0:00}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), i + 1);
                        //realkk += "'realkk'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        //pingzhangEmail += "'*****@*****.**'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        weight            += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), ((float)pi.Weight / 1000).ToString("0.0"));
                        JHT               += "'JHT International GmbH'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OttoBrennerStr    += "'Otto Brenner Str.'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        str4a             += "'4a'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        PLZ47877          += "'47877'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OrtWillich        += "'Willich'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        TelNr021548839989 += "'02154 8839989'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        deutschland       += "'Germany'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        recipientName     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.RecipientNameEn);
                        address           += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.AddressEn);
                        address2          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), " ");
                        address3          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), " ");
                        postCode          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PostCode);
                        provinceCity      += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.ProvinceCityEn);
                        china             += "'China'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        phoneNumber       += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PhoneNumber);
                        fullAddressCn     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.FullAddress);
                        milkPowder        += "'Milk powder'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        count             += "'10'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        moneyAmount       += "'115.90'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                    }

                    string endColumn = Excel.GetColumnIndex("D", packetInfos.Count - 1);
                    int    row       = 5;
                    //packTitle = "' ',' ',' '," + packTitle;
                    //excel.Insert("DHL申请表", string.Empty, packTitle);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), packTitle);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), JHT);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), OttoBrennerStr);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), str4a);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), PLZ47877);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), OrtWillich);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), TelNr021548839989);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), recipientName);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), postCode);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), provinceCity);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), phoneNumber);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), china);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), weight);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), milkPowder);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), moneyAmount);
                    //excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), realkk);
                    //excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), pingzhangEmail);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), deutschland);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address3);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), fullAddressCn);
                    ////row++;
                    ////row++;
                    ////row++;
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), count);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), weight);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        this,
                        "Error occured during inserting information into excel for dealworthier.\n" + ex.ToString(),
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    excel.Close();
                }

                return(destExcelFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    "Error occured during generating files for rainbow:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(string.Empty);
            }
        }
예제 #8
0
        private string GenerateRainbowFiles(List <PacketInfo> packetInfos, string folder)
        {
            try
            {
                string destExcelFile = CreateOutputFile(
                    Directory.GetParent(Application.ExecutablePath).FullName, RAINBOW_TEMPLATE_FILENAME,
                    folder, RAINBOW_EXCEL_OUTPUT_FILENAME);
                #region error message
                if (string.IsNullOrEmpty(destExcelFile))
                {
                    MessageBox.Show(
                        this,
                        "Create excel file for rainbow failed.\nMaybe rainbow template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(string.Empty);
                }
                #endregion

                Excel rainbowExcel = new Excel(destExcelFile);

                try
                {
                    string packTitle         = string.Empty;
                    string pingzhangEmail    = string.Empty;
                    string realkk            = string.Empty;
                    string JHT               = string.Empty;
                    string OttoBrennerStr4a  = string.Empty;
                    string PLZ47877          = string.Empty;
                    string OrtWillich        = string.Empty;
                    string TelNr021548839989 = string.Empty;
                    string recipientName     = string.Empty;
                    string address           = string.Empty;
                    string postCode          = string.Empty;
                    string provinceCity      = string.Empty;
                    string phoneNumber       = string.Empty;
                    string china             = string.Empty;
                    string item              = string.Empty;
                    string count             = string.Empty;
                    string weight            = string.Empty;
                    string moneyAmount       = string.Empty;
                    string fullAddressCn     = string.Empty;

                    for (int i = 0; i < packetInfos.Count; i++)
                    {
                        PacketInfo pi = packetInfos[i];
                        packTitle         += string.Format("'包裹单{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), i + 1);
                        pingzhangEmail    += "'*****@*****.**'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        realkk            += "'realkk'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        JHT               += "'JHT International GmbH'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OttoBrennerStr4a  += "'Otto Brenner Str.4a'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        PLZ47877          += "'47877'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OrtWillich        += "'Willich'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        TelNr021548839989 += "'02154 8839989'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        recipientName     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.RecipientNameEn);
                        address           += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.AddressEn);
                        postCode          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PostCode);
                        provinceCity      += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.ProvinceCityEn);
                        phoneNumber       += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PhoneNumber);
                        china             += "'China'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        item              += "'Milk powder'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        count             += "'10'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        weight            += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), (pi.Weight / 1000).ToString("0"));
                        moneyAmount       += "'115.90'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        fullAddressCn     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.FullAddress);
                    }

                    string endColumn = Excel.GetColumnIndex("C", packetInfos.Count - 1);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 1, endColumn), packTitle);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 2, endColumn), pingzhangEmail);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 3, endColumn), realkk);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 5, endColumn), JHT);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 6, endColumn), OttoBrennerStr4a);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 7, endColumn), PLZ47877);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 8, endColumn), OrtWillich);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 9, endColumn), TelNr021548839989);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 10, endColumn), recipientName);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 11, endColumn), address);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 13, endColumn), postCode);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 14, endColumn), provinceCity);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 15, endColumn), phoneNumber);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 16, endColumn), china);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 17, endColumn), item);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 18, endColumn), count);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 19, endColumn), weight);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 20, endColumn), moneyAmount);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 21, endColumn), fullAddressCn);
                }
                finally
                {
                    rainbowExcel.Close();
                }

                return(destExcelFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    "Error occured during generating files for rainbow:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(string.Empty);
            }
        }
예제 #9
0
        private string GenerateSupermarketFiles(List <PacketInfo> packetInfos, string folder)
        {
            try
            {
                string destExcelFile = CreateOutputFile(
                    Directory.GetParent(Application.ExecutablePath).FullName, SUPERMARKET_TEMPLATE_FILENAME,
                    folder, SUPERMARKET_EXCEL_OUTPUT_FILENAME);
                #region error message
                if (string.IsNullOrEmpty(destExcelFile))
                {
                    MessageBox.Show(
                        this,
                        "Create excel file for supermarket failed.\nMaybe supermarket template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(string.Empty);
                }
                #endregion

                // Write data into excel.
                Excel supermarketExcel = new Excel(destExcelFile);

                try
                {
                    for (int i = 0; i < packetInfos.Count; i++)
                    {
                        PacketInfo pi = packetInfos[i];
                        if (!supermarketExcel.Insert("Sheet1", string.Empty, CreatePacketInfoSupermarketValues(i + 1, pi)))
                        {
                            #region error message
                            MessageBox.Show(
                                this,
                                "Error occured during write data into excel file for supermarket:" + pi.RecipientNameCn,
                                this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            #endregion
                            return(string.Empty);
                        }
                    }
                }
                catch (Exception ex)
                {
                    #region error message
                    MessageBox.Show(
                        this,
                        "Error occured during write data into excel file for supermarket:" + ex.ToString(),
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    #endregion
                    return(string.Empty);
                }
                finally
                {
                    supermarketExcel.Close();
                }

                return(destExcelFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    "Error occured during generating files for supermarket:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(string.Empty);
            }
        }
예제 #10
0
        public PacketDetailsControl(PacketInfo pi, int index)
        {
            _packetInfo = pi;
            InitializeComponent();
            lblIndex.Text = index.ToString();

            // Generate description for products.
            StringBuilder sbProducts = new StringBuilder();

            string[] itemInfos = _packetInfo.ProductInfo.Split('★');
            for (int i = 0; i < itemInfos.Length; i++)
            {
                string   itemInfo = itemInfos[i];
                string[] infos    = itemInfo.Split('☆');
                if (infos.Length < 3)
                {
                    continue;
                }

                bool cancelled = false;
                if (infos.Length >= 4)
                {
                    cancelled = (((Order.OrderStatus)Enum.Parse(typeof(Order.OrderStatus), infos[3])) == Order.OrderStatus.Closed);
                }
                if (cancelled)
                {
                    continue;
                }

                if (infos[0].Contains("加强包装费"))
                {
                    continue;
                }
                if (infos[0].Contains("气囊加固"))
                {
                    continue;
                }

                sbProducts.Append(string.Format("{0}; {1}\r\n", Order.SimplifyItemSubject(infos[0], true).Trim(), infos[2]));                 // [0]:title, [1]:amount.
            }

            if (sbProducts.Length > 2 && sbProducts.ToString().EndsWith("\r\n"))
            {
                sbProducts.Remove(sbProducts.Length - 2, 2);               // remove return at the end of string.
            }
            txtProduct.Text   = sbProducts.ToString();
            txtProduct.Height = txtProduct.PreferredSize.Height;

            cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 6000, 265));
            cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 8000, 275));
            cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 9000, 285));
            cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 10000, 300));
            cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 15000, 350));
            cboPackets.Items.Add(new Packet(PacketTypes.Rainbow, 20000, 420));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 5000, 239));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 5500, 245));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 6000, 250));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 6500, 255));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 7000, 260));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 7500, 265));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 8000, 270));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 8500, 275));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 9000, 290));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 9500, 295));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 10000, 300));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 10500, 310));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 11000, 323));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 11500, 334));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 12000, 344));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 12500, 354));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 13000, 364));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 14000, 374));
            cboPackets.Items.Add(new Packet(PacketTypes.Ouhua, 15000, 394));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 7000, 241));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 8000, 258));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 9000, 285));
            //cboPackets.Items.Add(new Packet(PacketTypes.Supermarket, 15000, 358));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 5000, 246));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 5500, 251));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 6000, 258));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 6500, 263));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 7000, 268));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 7500, 273));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 8000, 278));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 8500, 288));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 9000, 298));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 9500, 303));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 10000, 308));
            //cboPackets.Items.Add(new Packet(PacketTypes.Dealworthier, 10500, 320));

            for (int i = 0; i < cboPackets.Items.Count; i++)
            {
                Packet p = (Packet)cboPackets.Items[i];
                if (p.Type == _packetInfo.Type && p.Weight == _packetInfo.Weight)
                {
                    cboPackets.SelectedIndex = i;
                    break;
                }
            }

            // fill full original address.
            txtFullAddress.Text = _packetInfo.FullAddress;
            txtPhoneNumber.Text = _packetInfo.PhoneNumber;

            try             // If error occurs let operator edit address itself.
            {
                // Get post code.
                string postCode = string.Empty;
                Regex  regex    = new Regex(@"(\(\d{6}\))|(,\d{6}$)");
                Match  m        = regex.Match(_packetInfo.FullAddress);
                //Trace.Assert(m.Success);
                if (m.Success)
                {
                    postCode         = m.Value;
                    postCode         = postCode.Replace("(", string.Empty).Replace(")", string.Empty).Replace(",", string.Empty);
                    txtPostCode.Text = postCode;
                }

                // Analyse address. Get information for original address.
                string[] recipientInfos = _packetInfo.FullAddress.Replace(m.Value, string.Empty).Trim().Split(',');
                txtRecipientName.Text = recipientInfos[0].Trim();

                // Get address details.
                string[] addressInfos = recipientInfos[recipientInfos.Length - 1].Split(' ');
                string   province     = string.Empty;
                string   city1        = string.Empty;
                string   city2        = string.Empty;
                foreach (string s in addressInfos)
                {
                    string ss = s.Trim();

                    if (ss.EndsWith("省") || ss.Equals("北京") || ss.Equals("上海") || ss.Equals("天津") || ss.Equals("重庆"))
                    {
                        province = ss;
                    }
                    if (ss.EndsWith("市") && !ss.StartsWith(province))
                    {
                        if (string.IsNullOrEmpty(city1))
                        {
                            city1 = ss;
                        }
                        else
                        {
                            city2 = ss;
                        }
                    }
                }
                if (!province.EndsWith("省") && !province.EndsWith("市"))                 // 直辖市.
                {
                    province += "市";
                }
                txtProvinceCity.Text = string.Format("{0} {1} {2}", province, city1, city2);

                // Get district;
                string   streetAddress      = RemoveStartingProvinceCity(recipientInfos[recipientInfos.Length - 1], province, city1, city2);
                string[] streetAddressInfos = streetAddress.Split(' ');                 // 此处如果还有空格分隔, 则认为第1个字符串是区. 但是如果买家在街道地址中也输入了空格, 可能出错.
                string   district           = string.Empty;
                if (streetAddressInfos.Length >= 2)
                {
                    district = streetAddressInfos[0];
                }
                if (!string.IsNullOrEmpty(district))
                {
                    streetAddress = streetAddress.Replace(district, string.Empty).Trim();
                }

                // 至此, 得到了去掉了前面的省市区的地址, 也即是买家在淘宝上手动输入的部分.
                // 需要去除买家可能重复输入的省市区信息.
                if (streetAddress.StartsWith(province))                 // remove starting province.
                {
                    streetAddress = streetAddress.Substring(province.Length, streetAddress.Length - province.Length);

                    // 如果是直辖市, 可能会在字符串首留下个"市".
                    if (streetAddress.StartsWith("市"))
                    {
                        streetAddress = streetAddress.Substring(1, streetAddress.Length - 1);
                    }
                }

                if (streetAddress.StartsWith(city1))                 // remove starting city1.
                {
                    streetAddress = streetAddress.Substring(city1.Length, streetAddress.Length - city1.Length);
                }

                if (streetAddress.StartsWith(city2))                 // remove starting city2.
                {
                    streetAddress = streetAddress.Substring(city2.Length, streetAddress.Length - city2.Length);
                }

                if (streetAddress.StartsWith(district))                 // remove starting district.
                {
                    streetAddress = streetAddress.Substring(district.Length, streetAddress.Length - district.Length);
                }

                txtStreetAddress.Text = district + streetAddress.Replace(m.Value, string.Empty);
            }
            catch {}
        }