operatecontrol.cs

来自「入门级asp.netC#网站三层系统开发」· CS 代码 · 共 44 行

CS
44
字号
using System;
using System.Collections.Generic;
using System.Text;
using DAL.Accessor;
using Common.Entities;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

//该源码下载自www.51aspx.com(51aspx.com)

namespace BLL
{
    public class OperateControl
    {
        //绑定下拉列表
        public static void BindDropDownList(DropDownList dropDownList,SqlDataReader reader,string value,string text)
        {
            while (reader.Read())
            {
                dropDownList.Items.Add(new ListItem(reader[text].ToString(), reader[value].ToString()));
            }
            reader.Dispose();
        }
        //上传文件
        public static string UpLoad(HtmlInputFile file, string saveFile)
        {
            //获取文件路径
            string fileName = file.PostedFile.FileName;
            //获取文件的后缀
            string extendName = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();
            string newName = null;
            //过滤文件的后缀
            if (extendName == "jpg" || extendName == "bmp")
            {
                DateTime now = DateTime.Now;
                newName = now.Year.ToString() + now.Month.ToString() + now.Day.ToString() + now.Hour.ToString() + now.Minute.ToString() + now.Second.ToString();
                file.PostedFile.SaveAs(saveFile + "/" + newName + "." + extendName);
            }
            return newName + "." + extendName;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?