コード例 #1
0
        private void DownloadFile(int fileID)
        {
            To_PolicyFileManager fileBLL    = new To_PolicyFileManager();
            To_PolicyFile        fileEntity = fileBLL.GetModel(fileID);

            if (fileEntity == null)
            {
                form1.InnerHtml = "<p style='font-size:14px;'>附件不存在或已被删除!</p>";
                return;
            }

            string filePath = fileEntity.filepath;
            string fileName = fileEntity.filename;

            if (Request.Browser.Browser == "IE")
            {
                fileName = Server.UrlEncode(fileName);
            }

            Response.Clear();
            Response.Buffer          = false;
            Response.ContentEncoding = System.Text.Encoding.UTF8; //注意编码

            Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
            //设置输出流HttpMiME类型(导出文件格式)
            Response.ContentType = "application/octet-stream;"; //image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
            Response.WriteFile(Server.MapPath(filePath));
        }
コード例 #2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <To_PolicyFile> DataTableToList(DataTable dt)
        {
            List <To_PolicyFile> modelList = new List <To_PolicyFile>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                To_PolicyFile model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new To_PolicyFile();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["policyID"].ToString() != "")
                    {
                        model.policyID = int.Parse(dt.Rows[n]["policyID"].ToString());
                    }
                    model.filename = dt.Rows[n]["filename"].ToString();
                    model.filepath = dt.Rows[n]["filepath"].ToString();
                    if (dt.Rows[n]["createTime"].ToString() != "")
                    {
                        model.createTime = DateTime.Parse(dt.Rows[n]["createTime"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return(modelList);
        }
コード例 #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public To_PolicyFile GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, policyID, filename, filepath, createTime,filesize  ");
            strSql.Append("  from To_PolicyFile ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;


            To_PolicyFile model = new To_PolicyFile();
            DataTable     ds    = DBHelper.GetDataSet(strSql.ToString(), parameters);

            if (ds.Rows.Count > 0)
            {
                if (ds.Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Rows[0]["id"].ToString());
                }
                if (ds.Rows[0]["policyID"].ToString() != "")
                {
                    model.policyID = int.Parse(ds.Rows[0]["policyID"].ToString());
                }
                if (ds.Rows[0]["filesize"].ToString() != "")
                {
                    model.Filesize = int.Parse(ds.Rows[0]["filesize"].ToString());
                }
                model.filename = ds.Rows[0]["filename"].ToString();
                model.filepath = ds.Rows[0]["filepath"].ToString();
                if (ds.Rows[0]["createTime"].ToString() != "")
                {
                    model.createTime = DateTime.Parse(ds.Rows[0]["createTime"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(To_PolicyFile model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into To_PolicyFile(");
            strSql.Append("policyID,filename,filepath,createTime,filesize");
            strSql.Append(") values (");
            strSql.Append("@policyID,@filename,@filepath,@createTime,@filesize");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@policyID",   SqlDbType.Int,         4),
                new SqlParameter("@filename",   SqlDbType.NVarChar,  100),
                new SqlParameter("@filepath",   SqlDbType.NVarChar,  500),
                new SqlParameter("@createTime", SqlDbType.DateTime),
                new SqlParameter("@filesize",   SqlDbType.Int)
            };

            parameters[0].Value = model.policyID;
            parameters[1].Value = model.filename;
            parameters[2].Value = model.filepath;
            parameters[3].Value = model.createTime;
            parameters[4].Value = model.Filesize;

            using (SqlConnection conn = new SqlConnection(DBHelper.connectionString))
            {
                using (SqlCommand sqlCmd = new SqlCommand())
                {
                    conn.Open();
                    sqlCmd.CommandText = strSql.ToString();
                    sqlCmd.Connection  = conn;
                    sqlCmd.Parameters.AddRange(parameters);

                    object objResult = sqlCmd.ExecuteScalar();

                    return(objResult != null && objResult != DBNull.Value ? Convert.ToInt32(objResult) : 0);
                }
            }
        }
コード例 #5
0
ファイル: AddPolicy.aspx.cs プロジェクト: zxmajunhong/wanghai
        /// <summary>
        /// 将附件信息保存到数据库
        /// </summary>
        /// <param name="fileList"></param>
        /// <param name="policID"></param>
        private void SaveFilePath(string[] fileList, int policID)
        {
            To_PolicyFileManager policyFileBLL    = new To_PolicyFileManager();
            To_PolicyFile        policyFileEntity = new To_PolicyFile();

            policyFileEntity.policyID = policID;

            for (int i = 1; i < 6; i++)
            {
                if (fileList[i] != "")
                {
                    string[] fileInfo = fileList[i].Split('|');

                    policyFileEntity.Filesize   = int.Parse(fileInfo[1]);
                    policyFileEntity.filepath   = fileInfo[0];
                    policyFileEntity.filename   = fileInfo[2];
                    policyFileEntity.createTime = DateTime.Now;

                    policyFileBLL.Add(policyFileEntity);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(To_PolicyFile model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update To_PolicyFile set ");

            strSql.Append(" policyID = @policyID , ");
            strSql.Append(" filename = @filename , ");
            strSql.Append(" filepath = @filepath , ");
            strSql.Append(" createTime = @createTime  ");
            strSql.Append(" where id=@id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@id",         SqlDbType.Int,        4),
                new SqlParameter("@policyID",   SqlDbType.Int,        4),
                new SqlParameter("@filename",   SqlDbType.NVarChar, 100),
                new SqlParameter("@filepath",   SqlDbType.NVarChar,  50),
                new SqlParameter("@createTime", SqlDbType.DateTime)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.policyID;
            parameters[2].Value = model.filename;
            parameters[3].Value = model.filepath;
            parameters[4].Value = model.createTime;
            int rows = DBHelper.ExecuteScalar(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(To_PolicyFile model)
 {
     return(dal.Update(model));
 }
コード例 #8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(To_PolicyFile model)
 {
     return(dal.Add(model));
 }