Beispiel #1
0
        protected void imgImportData_Click(object sender, ImageClickEventArgs e)
        {
            //Thread.Sleep(1000000);
            try
            {
                //ImageButton1.ImageUrl = @"~/Images/importing.png";
                #region 订单交易导入
                if (!String.IsNullOrEmpty(fileOrderUpload.PostedFile.FileName))
                {
                    //文件扩展名
                    string fileExtend = "";
                    string filePath   = "";
                    //文件大小
                    long fileSize = 0;
                    filePath = fileOrderUpload.PostedFile.FileName.ToLower().Trim();

                    //取得上传前的文件(存在于客户端)的文件或文件夹的名称
                    string[] names = filePath.Split('\\');
                    //取得文件名
                    string name = names[names.Length - 1];
                    //获得服务器端的根目录
                    string serverPath = Server.MapPath("~/SellerReport");

                    //判断是否有该目录
                    if (!Directory.Exists(serverPath))
                    {
                        Directory.CreateDirectory(serverPath);
                    }
                    filePath = serverPath + "\\" + name;
                    var fileImprtPath = serverPath + "\\";
                    //如果存在,删除文件
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                    // 上传文件
                    fileOrderUpload.PostedFile.SaveAs(filePath);


                    //得到扩展名
                    fileExtend = filePath.Substring(filePath.LastIndexOf("."));
                    if (fileExtend != ".csv")
                    {
                        lbError.Text      = "只支持CSV格式的文件!";
                        lbError.ForeColor = Color.Red;
                        return;
                    }

                    System.IO.FileInfo f = new FileInfo(filePath);
                    fileSize = f.Length;
                    int size = Convert.ToInt32(fileSize) / (1024 * 1024);
                    if (size >= 20)
                    {
                        lbError.Text      = "最大可上传文件大小为20M!";
                        lbError.ForeColor = Color.Red;
                        return;
                    }

                    CSVHelper obj  = new CSVHelper(fileImprtPath, fileOrderUpload.FileName.ToLower().Trim());
                    DataTable tb   = obj.Read();
                    long      tick = DateTime.Now.Ticks;
                    Random    ran  = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
                    //将订单交易信息写入到DB,同时更新买家表信息
                    if (tb != null && tb.Rows.Count > 0)
                    {
                        Trade  o        = null;
                        Buyers objBuyer = null;


                        foreach (DataRow row in tb.Rows)
                        {
                            try
                            {
                                o = new Trade();
                                //o.Tid = Convert.ToInt64(string.IsNullOrEmpty(row["订单编号"].ToString()) ? "000000" : row["订单编号"].ToString());
                                o.BuyerNick       = row["买家会员名"].ToString();
                                o.SellerNick      = Users.Nick;
                                o.ReceiverAddress = row["收货地址 "].ToString();
                                o.ReceiverName    = row["收货人姓名"].ToString();
                                o.ReceiverPhone   = row["联系电话 "].ToString();
                                o.ReceiverMobile  = row["联系手机"].ToString();

                                //更新买家信息表数据
                                objBuyer         = new Buyers();
                                objBuyer.Address = o.ReceiverAddress;
                                if (!String.IsNullOrEmpty(o.ReceiverAddress))
                                {
                                    string[] info = o.ReceiverAddress.Split(new char[] { ' ' });
                                    if (info.Length > 0)
                                    {
                                        objBuyer.BuyerProvince = info[0].ToString();
                                    }
                                }
                                objBuyer.BuyerId         = Convert.ToInt64(ran.Next().ToString());
                                objBuyer.BuyerNick       = o.BuyerNick;
                                objBuyer.CellPhone       = o.ReceiverMobile == null ? "" : o.ReceiverMobile.Replace("'", "");
                                objBuyer.Phone           = o.ReceiverPhone == null ? "" : o.ReceiverPhone.Replace("'", "");
                                objBuyer.Buyer_reallName = String.IsNullOrEmpty(o.ReceiverName) ? "unknown!" : o.ReceiverName;
                                objBuyer.SELLER_ID       = Users.Nick;
                                objBuyer.UpdateDate      = DateTime.Now.ToString();
                                objBuyer.LastTradeTime   = Convert.ToString(row["订单付款时间 "]);
                                objBuyer.TradeAmount     = row["买家实际支付金额"].ToString();
                                objBuyer.ItemNum         = Convert.ToInt64(row["宝贝总数量"]);
                                objBuyer.TradeCount      = 1L;
                                objBuyer.Grade           = 1;
                                objBuyer.Address         = o.ReceiverAddress;
                                if (BuyerBLL.CheckBuyerIsExit(objBuyer.BuyerNick, Users.Nick, sellerId))
                                {
                                    BuyerBLL.UpdateForHistory(objBuyer, sellerId);
                                }
                                else
                                {
                                    BuyerBLL.AddBuyerBySeller(objBuyer);
                                }
                            }
                            catch (Exception ex)
                            {
                                //ExceptionReporter.WriteLog(ex, ExceptionPostion.TBApply_Web_UI);
                                continue;
                            }
                        }
                        //将最新同步数据时间更新写入DB
                        Sellers objSeller = new Sellers();
                        objSeller.Nick = Users.Nick;
                        SellersBLL.UpdateSellerSynDate(objSeller);
                    }

                    lbError.Text = "导入报表数据成功!";
                }
                else
                {
                    lbError.Text = "请选择小于20M的CSV格式文件!";
                }
                //ImageButton1.ImageUrl = @"~/Images/import.png";
                #endregion
            }

            catch (Exception ex)
            {
                ExceptionReporter.WriteLog(ex, ExceptionPostion.TBApply_Data);
                //lbError.Text = "导入报表失败,请联系客服!";
                lbError.Text      = "导入报表失败,报表内容格式不正确!";
                lbError.ForeColor = Color.Red;
                //ImageButton1.ImageUrl = @"~/Images/import.png";
                return;
            }
        }
Beispiel #2
0
        protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
        {
            //判断输入格式
            if (!String.IsNullOrEmpty(txtCellphone.Text.Trim()) && !Utility.IsCellPhone(txtCellphone.Text.Trim()))
            {
                lbCellPhoneError.Text = "手机号码格式不正确!";
                return;
            }
            if (string.IsNullOrEmpty(txtCellphone.Text.Trim()))
            {
                lbCellPhoneError.Text = "手机号码不能为空!";
                return;
            }

            if (!String.IsNullOrEmpty(txtPhone.Text.Trim()) && !Utility.IsPhone(txtPhone.Text.Trim()))
            {
                lbPhoneError.Text = "座机号码格式不正确!";
                return;
            }
            if (!String.IsNullOrEmpty(txtQQ.Text.Trim()) && !Utility.IsNumeric(txtQQ.Text.Trim()))
            {
                lbQQError.Text = "QQ号码应该都是数字!";
                return;
            }
            if (!String.IsNullOrEmpty(txtEmail.Text.Trim()) && !Utility.IsEmail(txtEmail.Text.Trim()))
            {
                lbQQError.Text = "Email格式不正确!";
                return;
            }
            if (!String.IsNullOrEmpty(txtZIPCode.Text.Trim()) && !Utility.IsZIPCode(txtZIPCode.Text.Trim()))
            {
                lbZIPError.Text = "邮编格式不正确!";
                return;
            }

            //相同手机号码只能添加一次
            if (BuyerBLL.CheckTheSameHPNoIsExit(Users.Nick, txtCellphone.Text.Trim()))
            {
                lbMsg.Text      = "手机号码重复,系统已经存在该号码!";
                lbMsg.ForeColor = Color.Red;
                txtCellphone.Focus();
                return;
            }

            Buyers objBuyer = new Buyers();
            long   tick     = DateTime.Now.Ticks;
            Random ran      = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));

            objBuyer.BuyerId         = Convert.ToInt64(ran.Next().ToString());
            objBuyer.SELLER_ID       = Users.Nick;
            objBuyer.BuyerNick       = txtNick.Text.Trim();
            objBuyer.Buyer_reallName = txtRealName.Text.Trim();
            objBuyer.CellPhone       = txtCellphone.Text.Trim();
            objBuyer.Phone           = txtPhone.Text.Trim();
            objBuyer.QQ            = txtQQ.Text.Trim();
            objBuyer.MSN           = txtMSN.Text.Trim();
            objBuyer.ZipCode       = txtZIPCode.Text.Trim();
            objBuyer.Email         = txtEmail.Text.Trim();
            objBuyer.SinaWeibo     = txtsinaWeibo.Text.Trim();
            objBuyer.QQWeibo       = txtQQWeibo.Text.Trim();
            objBuyer.BuyerProvince = drpArea.SelectedValue.ToString();
            objBuyer.City          = txtCity.Text.Trim();
            objBuyer.birthDay      = datebirthday.Value.ToString();
            objBuyer.BuyerType     = "2";
            try
            {
                if (BuyerBLL.AddBuyerBySeller(objBuyer))
                {
                    lbMsg.Text      = "会员信息添加成功!";
                    lbMsg.ForeColor = Color.Blue;
                    txtCellphone.Focus();
                    txtCellphone.Text = "";
                }
            }
            catch (Exception ex)
            {
                lbMsg.Text = "添加会员失败!";
                ExceptionReporter.WriteLog(ex, ExceptionPostion.TBApply_Web_UI);
            }
        }