• 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);
            }
        }
  • 相关阅读:
    工作之:oracle 11g deferred_segment_creation段延迟创建(转载他人)
    工作之:数据库锁表问题
    工作之:weblogic的url 使用weblogic连接RAC数据库的方式配置如下
    Oracle和Mysql的区别 转载
    关于fastjson的一些知识
    进程和线程的区别 转载
    同一进程中的线程共享的资源有哪些 转载
    2015-04-20一些知识点
    Java中String类型详解
    2015-04-14一些知识点
  • 原文地址:https://www.cnblogs.com/chusiping/p/2753181.html
Copyright © 2020-2023  润新知