Exemplo n.º 1
0
        void linkUpload_Click(object sender, EventArgs e)
        {
            if (!fileCheck.HasFile)
            {
                this.ShowMsg("请选择文件!", false);
                return;
            }
            DataTable dt;

            string name       = fileCheck.PostedFile.FileName;
            string path       = Server.MapPath("/userloadfile/") + name;
            string expandName = fileCheck.FileName.Substring(name.LastIndexOf('.') + 1);

            //上传支付宝对账单
            if (ddlUploadingCheck.SelectedValue == "1")
            {
                //this.fileCheck.PostedFile.SaveAs(path);
                if (expandName.ToLower() == "csv")
                {
                    Stream       stream = fileCheck.PostedFile.InputStream;
                    StreamReader sr     = new StreamReader(stream, Encoding.GetEncoding("GB2312"));
                    string       str    = "";
                    string       s      = sr.ReadLine();
                    s = sr.ReadLine();
                    string accountId = "";
                    if (s != null)
                    {
                        if (s.Contains("["))
                        {
                            accountId = s.Substring(s.IndexOf('[') + 1);
                            accountId = accountId.Replace("]", "").Replace(",", "").Replace("\"", "").Replace("\t", "");
                        }
                    }
                    //获取起始日期 终止日期
                    s = sr.ReadLine();
                    DateTime?beginTime = null;
                    DateTime?endTime   = null;

                    System.Collections.Generic.List <string[]> list = new System.Collections.Generic.List <string[]>();
                    while (str != null)
                    {
                        str = sr.ReadLine();
                        if (str != null)
                        {
                            string[] xu = str.Replace("\t", "").Replace("\"", "").Split(',');
                            if (xu != null && xu.Length >= 12)
                            {
                                if (IsNumber(xu[0]))
                                {
                                    list.Add(xu);
                                }
                            }
                        }
                    }
                    sr.Close();
                    stream.Close();
                    dt = CVSToDataTable(list, accountId);
                    if (dt.Rows.Count > 0)
                    {
                        dt.DefaultView.Sort = "CreateTime asc";     //重新设置排序
                        DataTable dtNew = dt.DefaultView.ToTable(); //保存在一张新表中
                        dt.Dispose();
                        beginTime = (DateTime)dtNew.Rows[0]["CreateTime"];
                        endTime   = (DateTime)dtNew.Rows[dtNew.Rows.Count - 1]["CreateTime"];
                        MemberProcessor.DeleteEcshop_TradeDetails(beginTime, endTime, "AliPay");
                        Exception ex;
                        if (MemberProcessor.DataTableAddToTradeDetails(dtNew, out ex))
                        {
                            this.ShowMsg("文件上传成功!", true);
                        }
                        else
                        {
                            this.ShowMsg("文件上传失败!错误:" + ex.Message, false);
                        }
                    }
                    return;
                }
                else
                {
                    this.ShowMsg("上传支付对账单时请上传CVS格式文件!", false);
                    return;
                }
            }

            this.ShowMsg("文件上传成功!", true);
        }