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);
            }
        }
  • 相关阅读:
    golang学习之旅:官方文档汇总
    golang学习之旅:搭建go语言开发环境
    《编码》读书笔记:从无到有构建计算机系统
    在Eclipse中如何关联spring-framework的文档和源代码
    Java中Unicode的编码和实现
    个人常用工具整理
    battery-historian结果分析
    电量分析工具 Battery Historian 的配置及使用
    appium使用常见问题汇总--持续更新
    appium连接夜神模拟器方法总结
  • 原文地址:https://www.cnblogs.com/chusiping/p/2753181.html
Copyright © 2011-2022 走看看