zoukankan      html  css  js  c++  java
  • gw经销商上传部分代码

    protected void btnSave_Click(object sender, EventArgs e)
        {
            string filePath = "";
            if (FileUpload1.HasFile)
            {
                string fileType = System.IO.Path.GetExtension(FileUpload1.FileName).ToString();
                CN_T_Sysdictionary dicModel = CN_T_SysdictionaryDal.cn_t_SysdictionaryDal.GetModel(" key='经销商在线附件类型'");
                string defaultFileType = ".rar|.zip|.doc|.docx";//默认格式
                if (dicModel != null)
                {
                    defaultFileType = dicModel.VALUE;
                }
    
                if (dicModel.VALUE.Contains(fileType))
                {
                    int fileLenth = FileUpload1.PostedFile.ContentLength;
                    CN_T_Sysdictionary dicSizeModel = CN_T_SysdictionaryDal.cn_t_SysdictionaryDal.GetModel(" dicname='经销商在线附件大小'");
                    int dicSize = 2 * 1024 * 1024;//默认文件大小
                    if (dicSizeModel != null)
                    {
                        dicSize = Convert.ToInt32(dicSizeModel.VALUE) * 1024 * 1024;
                    }
                    if (fileLenth <= dicSize)
                    {
                        //edit by jarry 2012-11-4 增加随机文件名
                        int index = FileUpload1.FileName.LastIndexOf(".");
                        string lastName = FileUpload1.FileName.Substring(index, FileUpload1.FileName.Length - index);//文件后缀
                        string newname = DateTime.Now.ToString("yyyyMMddhhmmss") + lastName;//新文件名
                        filePath = "../uploads/" + newname;
                    }
                    else
                    {
                        ScriptHelper.Alert("上传文件大小不能超过:" + dicSizeModel.VALUE + "M");
                        return;
                    }
                }
                else
                {
                    ScriptHelper.Alert("上传文件的类型只能为" + dicModel.VALUE);
                    return;
                }
            }
    
            string userName = txtUserName.Text.Replace("#", "");
            string unit = txtUnit.Text.Replace("#", "");
            string address = txtAddress.Text.Replace("#", "");
            string email = txtEmail.Text.Replace("#", "");
            string qq = txtQQ.Text;
            string phone = txtPhone.Text;
            string content = txtContent.Text.Replace("#", "");
    
            StringBuilder msgContent = new StringBuilder();
            msgContent.Append(userName);
            msgContent.Append("#");
            msgContent.Append(unit);
            msgContent.Append("#");
            msgContent.Append(address);
            msgContent.Append("#");
            msgContent.Append(email);
            msgContent.Append("#");
            msgContent.Append(qq);
            msgContent.Append("#");
            msgContent.Append(phone);
            msgContent.Append("#");
            msgContent.Append(content);
    
            CN_T_UserMsg model = new CN_T_UserMsg();
            model.BYDOMAIN = "官网";
            model.TITLE = "经销商在线问答";
            model.MSGCONTENT = msgContent.ToString();
            model.ISSHOW = 0;
            model.TYPE = "经销商在线问答";
            model.FILEPATH = filePath;
            try
            {
                CN_T_UserMsgDAL.cN_T_UserMsgDAL.Add(model);
                if (FileUpload1.HasFile)
                {
                    FileUpload1.SaveAs(Server.MapPath(filePath));
                }
                InputClearText();// 清空所有文本
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('提交成功!')", true);
            }
            catch
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('提交失败!')", true);
            }
        }
  • 相关阅读:
    【BZOJ】【1833】【ZJOI2010】count 数字计数
    bzoj2588: Spoj 10628. Count on a tree(树上第k大)(主席树)
    NOIP2017金秋冲刺训练营杯联赛模拟大奖赛第一轮Day2题解
    NOIP2017金秋冲刺训练营杯联赛模拟大奖赛第二轮Day2题解
    51nod 1962 区间计数(单调栈+二分)
    51nod 1486 大大走格子(DP+组合数学)
    bzoj2276: [Poi2011]Temperature(单调队列/堆)
    5028: 小Z的加油店(线段树)
    bzoj2216: [Poi2011]Lightning Conductor(分治决策单调性优化)
    bzoj1057: [ZJOI2007]棋盘制作(悬线法)
  • 原文地址:https://www.cnblogs.com/chusiping/p/2753181.html
Copyright © 2011-2022 走看看