コード例 #1
0
    protected void bt_UploadExcel_Click(object sender, EventArgs e)
    {
        #region 保存文件
        if (!FileUpload1.HasFile)
        {
            MessageBox.Show(this.Page, "请选择要上传的文件!");
            return;
        }
        int FileSize = (FileUpload1.PostedFile.ContentLength / 1024);

        if (FileSize > ConfigHelper.GetConfigInt("MaxAttachmentSize"))
        {
            MessageBox.Show(this.Page, "上传的文件不能大于" + ConfigHelper.GetConfigInt("MaxAttachmentSize") +
                "KB!当前上传文件大小为:" + FileSize.ToString() + "KB");
            return;
        }

        //判断文件格式
        string FileName = FileUpload1.PostedFile.FileName;
        FileName = FileName.Substring(FileName.LastIndexOf('\\') + 1);
        FileName = FileName.Substring(0, FileName.LastIndexOf('.'));

        string FileExtName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".") + 1).ToLowerInvariant();

        if (FileExtName != "xls" && FileExtName != "csv")
        {
            MessageBox.Show(this, "对不起,必须上传扩展名为xls的Excel文件!");
            return;
        }

        string path = ConfigHelper.GetConfigString("AttachmentPath");
        if (path.StartsWith("~")) path = Server.MapPath(path);
        if (!path.EndsWith("\\")) path = path + "\\";
        path += "ImportExcelSVM\\Upload\\" + ddl_AccountMonth.SelectedValue + "\\";
        if (!Directory.Exists(path)) Directory.CreateDirectory(path);

        path += FileName + "." + FileExtName;

        FileUpload1.SaveAs(path);
        #endregion

        SVM_UploadTemplateBLL _bll = new SVM_UploadTemplateBLL();
        _bll.Model.Name = FileName + "." + FileExtName; ;
        _bll.Model.AccountMonth = int.Parse(ddl_AccountMonth.SelectedValue);
        _bll.Model.State = 1;
        _bll.Model.IsOpponent =MCSTabControl1.SelectedIndex==1? 2:3;
        _bll.Model.InsertStaff = (int)Session["UserID"];
        _bll.Model.UploadTime = DateTime.Now;
        _bll.Model["UserName"] = Session["UserName"].ToString();
        _bll.Add();
        Response.Redirect("ImportHistory.aspx?IsOpponent=" + (MCSTabControl1.SelectedIndex == 1 ? "2" : "3") + "&State=2");
    }
コード例 #2
0
    protected void bt_UploadExcel_Click(object sender, EventArgs e)
    {
        #region 保存文件
        if (!FileUpload1.HasFile)
        {
            MessageBox.Show(this.Page, "请选择要上传的文件!");
            return;
        }
        int FileSize = (FileUpload1.PostedFile.ContentLength / 1024);

        if (FileSize > ConfigHelper.GetConfigInt("MaxAttachmentSize"))
        {
            MessageBox.Show(this.Page, "上传的文件不能大于" + ConfigHelper.GetConfigInt("MaxAttachmentSize") +
                "KB!当前上传文件大小为:" + FileSize.ToString() + "KB");
            return;
        }

        //判断文件格式
        string FileName = FileUpload1.PostedFile.FileName;
        FileName = FileName.Substring(FileName.LastIndexOf('\\') + 1);
        FileName = FileName.Substring(0, FileName.LastIndexOf('.'));

        string FileExtName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".") + 1).ToLowerInvariant();

        if (FileExtName != "xls" &&FileExtName != "csv")
        {
            MessageBox.Show(this, "对不起,必须上传扩展名为xls的Excel文件!");
            return;
        }

        string path = ConfigHelper.GetConfigString("AttachmentPath");
        if (path.StartsWith("~")) path = Server.MapPath(path);
        if (!path.EndsWith("\\")) path = path + "\\";
        path += "ImportExcelSVM\\Upload\\" + Session["UserName"].ToString() + "\\";
        if (!Directory.Exists(path)) Directory.CreateDirectory(path);

        path += FileName + "." + FileExtName;

        FileUpload1.SaveAs(path);
        #endregion

        SVM_UploadTemplateBLL _bll = new SVM_UploadTemplateBLL();
        _bll.Model.Name = FileName + "." + FileExtName; ;
        _bll.Model.AccountMonth = ((AC_AccountMonth)ViewState["month"]).ID;
        _bll.Model.State = 1;
        _bll.Model.IsOpponent = (int)ViewState["IsOpponent"];
        _bll.Model.InsertStaff = (int)Session["UserID"];
        _bll.Model.UploadTime = DateTime.Now;
        _bll.Model["UserName"] = Session["UserName"].ToString();
        _bll.Model["ClientType"] = ViewState["ClientType"].ToString();
        _bll.Add();
        div_gift.Visible = false;

        //StringBuilder builder = new StringBuilder();
        //builder.Append("alert('请到该页面查询导入状态!');");
        //builder.Append("window.open('ImportHistory.aspx?IsOpponent=" + ViewState["IsOpponent"].ToString() + "&State=2&ClientType=" + ViewState["ClientType"].ToString() + "','_blank')");

        //MessageBox.ResponseScript(this, builder.ToString());
        Response.Redirect("ImportHistory.aspx?IsOpponent=" + ViewState["IsOpponent"].ToString() + "&State=2&ClientType=" + ViewState["ClientType"].ToString());
    }
コード例 #3
0
    protected void bt_UploadExcel_Click(object sender, EventArgs e)
    {
        #region 保存文件
        if (!FileUpload1.HasFile)
        {
            MessageBox.Show(this.Page, "请选择要上传的文件!");
            return;
        }
        int FileSize = (FileUpload1.PostedFile.ContentLength / 1024);

        if (FileSize > ConfigHelper.GetConfigInt("MaxAttachmentSize"))
        {
            MessageBox.Show(this.Page, "上传的文件不能大于" + ConfigHelper.GetConfigInt("MaxAttachmentSize") +
                            "KB!当前上传文件大小为:" + FileSize.ToString() + "KB");
            return;
        }

        //判断文件格式
        string FileName = FileUpload1.PostedFile.FileName;
        FileName = FileName.Substring(FileName.LastIndexOf('\\') + 1);
        FileName = FileName.Substring(0, FileName.LastIndexOf('.'));

        string FileExtName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".") + 1).ToLowerInvariant();

        if (FileExtName != "xls" && FileExtName != "csv")
        {
            MessageBox.Show(this, "对不起,必须上传扩展名为xls的Excel文件!");
            return;
        }

        string path = ConfigHelper.GetConfigString("AttachmentPath");
        if (path.StartsWith("~"))
        {
            path = Server.MapPath(path);
        }
        if (!path.EndsWith("\\"))
        {
            path = path + "\\";
        }
        path += "ImportExcelSVM\\Upload\\" + Session["UserName"].ToString() + "\\";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        path += FileName + "." + FileExtName;

        FileUpload1.SaveAs(path);
        #endregion

        SVM_UploadTemplateBLL _bll = new SVM_UploadTemplateBLL();
        _bll.Model.Name          = FileName + "." + FileExtName;;
        _bll.Model.AccountMonth  = ((AC_AccountMonth)ViewState["month"]).ID;
        _bll.Model.State         = 1;
        _bll.Model.IsOpponent    = (int)ViewState["IsOpponent"];
        _bll.Model.InsertStaff   = (int)Session["UserID"];
        _bll.Model.UploadTime    = DateTime.Now;
        _bll.Model["UserName"]   = Session["UserName"].ToString();
        _bll.Model["ClientType"] = ViewState["ClientType"].ToString();
        _bll.Add();
        div_gift.Visible = false;

        //StringBuilder builder = new StringBuilder();
        //builder.Append("alert('请到该页面查询导入状态!');");
        //builder.Append("window.open('ImportHistory.aspx?IsOpponent=" + ViewState["IsOpponent"].ToString() + "&State=2&ClientType=" + ViewState["ClientType"].ToString() + "','_blank')");

        //MessageBox.ResponseScript(this, builder.ToString());
        Response.Redirect("ImportHistory.aspx?IsOpponent=" + ViewState["IsOpponent"].ToString() + "&State=2&ClientType=" + ViewState["ClientType"].ToString());
    }
コード例 #4
0
    protected void bt_UploadExcel_Click(object sender, EventArgs e)
    {
        #region 保存文件
        if (!FileUpload1.HasFile)
        {
            MessageBox.Show(this.Page, "请选择要上传的文件!");
            return;
        }
        int FileSize = (FileUpload1.PostedFile.ContentLength / 1024);

        if (FileSize > ConfigHelper.GetConfigInt("MaxAttachmentSize"))
        {
            MessageBox.Show(this.Page, "上传的文件不能大于" + ConfigHelper.GetConfigInt("MaxAttachmentSize") +
                            "KB!当前上传文件大小为:" + FileSize.ToString() + "KB");
            return;
        }

        //判断文件格式
        string FileName = FileUpload1.PostedFile.FileName;
        FileName = FileName.Substring(FileName.LastIndexOf('\\') + 1);
        FileName = FileName.Substring(0, FileName.LastIndexOf('.'));

        string FileExtName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".") + 1).ToLowerInvariant();

        if (FileExtName != "xls" && FileExtName != "csv")
        {
            MessageBox.Show(this, "对不起,必须上传扩展名为xls的Excel文件!");
            return;
        }

        string path = ConfigHelper.GetConfigString("AttachmentPath");
        if (path.StartsWith("~"))
        {
            path = Server.MapPath(path);
        }
        if (!path.EndsWith("\\"))
        {
            path = path + "\\";
        }
        path += "ImportExcelSVM\\Upload\\" + ddl_AccountMonth.SelectedValue + "\\";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        path += FileName + "." + FileExtName;

        FileUpload1.SaveAs(path);
        #endregion

        SVM_UploadTemplateBLL _bll = new SVM_UploadTemplateBLL();
        _bll.Model.Name         = FileName + "." + FileExtName;;
        _bll.Model.AccountMonth = int.Parse(ddl_AccountMonth.SelectedValue);
        _bll.Model.State        = 1;
        _bll.Model.IsOpponent   = MCSTabControl1.SelectedIndex == 1? 2:3;
        _bll.Model.InsertStaff  = (int)Session["UserID"];
        _bll.Model.UploadTime   = DateTime.Now;
        _bll.Model["UserName"]  = Session["UserName"].ToString();
        _bll.Add();
        Response.Redirect("ImportHistory.aspx?IsOpponent=" + (MCSTabControl1.SelectedIndex == 1 ? "2" : "3") + "&State=2");
    }