using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using ClassData;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Design;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using AlaOne.Common;
using System.IO;
namespace AlaOne.Common
{
/// <summary>
/// UpFileOnline 的摘要说明。
/// </summary>
public class UpFileOnline
{
DataConn dc=new DataConn();//数据操作接口
string strconn=ConfigurationSettings.AppSettings["AlaOne"];//数据库连接接口
string UploadNewsPath=ConfigurationSettings.AppSettings["UploadNewsPath"];//上传新闻图片保存路径
string UploadMagPath=ConfigurationSettings.AppSettings["UploadMagPath"];//上传杂志保存路径
string UploadSwfPath=ConfigurationSettings.AppSettings["UploadSwfPath"];//上传swf文件保存路径
string UploadVideoPath=ConfigurationSettings.AppSettings["UploadVideoPath"];//上传swf文件保存路径
string UploadCoverPath=ConfigurationSettings.AppSettings["UploadCoverPath"];//上传杂志封面路径
string UploadDownPath=ConfigurationSettings.AppSettings["UploadDownPath"];//上传杂志下载路径
string UploadMusicPath=ConfigurationSettings.AppSettings["UploadMusicPath"];//上传背景音乐路径
string LeadShowPhoto=ConfigurationSettings.AppSettings["LeadShowPhoto"];//上传LeasShowPhoto
public UpFileOnline()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 判断输入的字符串是否是数字
/// </summary>
/// <param name="Value">字符串</param>
/// <returns>true or false</returns>
public bool IsNumeric(string Value)
{
try
{
int i = int.Parse(Value);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 根据上传文件的名称,生成一个随机图片名称,并上传该图片!
/// </summary>
/// <param name="WebFile"></param>
/// <param name="strFileExt">图片扩展名</param>
/// <returns>返回该图片名称</returns>
public string UploadNewsPicsPath(System.Web.UI.HtmlControls.HtmlInputFile WebFile,string strFileExt)
{
string strFileName="";
strFileExt=strFileExt.ToLower();
if(strFileExt==".jpg")
{
RandomNum GetFileCode=new RandomNum();
strFileName=GetFileCode.PicsID();
strFileName=strFileName+".jpg";
UploadPicFile(WebFile,strFileName);
return strFileName;
}
if(strFileExt==".gif")
{
RandomNum GetFileCode=new RandomNum();
strFileName=GetFileCode.PicsID();
strFileName=strFileName+".gif";
UploadPicFile(WebFile,strFileName);
return strFileName;
}
if(strFileExt==".bmp")
{
RandomNum GetFileCode=new RandomNum();
strFileName=GetFileCode.PicsID();
strFileName=strFileName+".bmp";
UploadPicFile(WebFile,strFileName);
return strFileName;
}
if(strFileExt==".png")
{
RandomNum GetFileCode=new RandomNum();
strFileName=GetFileCode.PicsID();
strFileName=strFileName+".png";
UploadPicFile(WebFile,strFileName);
return strFileName;
}
else
{
return "";
}
}
public void UploadPicFile(System.Web.UI.HtmlControls.HtmlInputFile WebFile,string strFileName)
{
char[] spliter = {'\\'};
string [] FileName = strFileName.Split(spliter,10);
string FullPath = UploadNewsPath + @"\" + FileName[FileName.Length-1]; //生成完整文件名
string fromFullPath = UploadNewsPath + @"\" +"_new"+ FileName[FileName.Length-1]; //生成完整文件名
WebFile.PostedFile.SaveAs(fromFullPath); //保存文件
//// string extension=Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper();
//// string fileName=DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString();
//// string path=Server.MapPath(".")+"/img/"+fileName+extension;
//// UploadFile.PostedFile.SaveAs(path);
// //加文字水印,注意,这里的代码和以下加图片水印的代码不能共存
// System.Drawing.Image image=System.Drawing.Image.FromFile(path);
// Graphics g=Graphics.FromImage(image);
// g.DrawImage(image,0,0,image.Width,image.Height);
// Fontf=newFont("Verdana",32);
// Brushb=newSolidBrush(Color.White);
// stringaddText=AddText.Value.Trim();
// g.DrawString(addText,f,b,10,10);
// g.Dispose();