直播中
namespace cj168.Web.Mag.Admins.FeData
{
/// <summary>
/// Summary description for fedata.
/// </summary>
public class feUploadPic : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtboxPicTitle;
protected System.Web.UI.WebControls.Calendar calPicDate;
protected System.Web.UI.WebControls.DropDownList ddlPicType;
protected System.Web.UI.WebControls.TextBox txtboxPicIntro;
protected System.Web.UI.HtmlControls.HtmlInputFile filePicName;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.Label lblPicInfo;
protected System.Web.UI.WebControls.TextBox txtboxPicDate;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator vldCatName;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.CustomValidator CustomValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.HyperLink hlkOriPic;
protected System.Web.UI.WebControls.HyperLink hlkNewPic;
protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator2;
protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator3;
protected System.Web.UI.WebControls.CheckBoxList checkboxlistRewrite;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//if(Page.IsPostBack)
//txtboxPicDate.Text = calPicDate.SelectedDate.ToString();
if(!Page.IsPostBack)
{
Bind2DropDownListPicType();
//for(int i = 0;i < Request.Files.Count; i++)
//{
// checkboxlistRewrite.Items[i].Selected = false;
//}
}
}
public void Bind2DropDownListPicType()
{
cj168.DataAccess.Admins admins = new cj168.DataAccess.Admins();
DataSet ds = admins.FePicTypeGet();
//ddlPicType.DataSource = ;
DataView dv = new DataView(ds.Tables["PicType"]);
DataRowView drv = dv.AddNew();
//DataColumnView dcv = dv.AddNew();
drv["Title"] = "請(qǐng)選擇";
drv["fePicTypeID"] = "0";
drv.EndEdit();
dv.Sort = "fePicTypeID";
ddlPicType.DataSource = dv;
ddlPicType.DataBind();
}
public void UploadFile(object sender, System.EventArgs e)
{
string imgNameOnly, imgNameNoExt, imgExt;
string imgThumbnail;
int erroNumber = 0;
System.Drawing.Image oriImg, newImg;
string strFePicSavePath = ConfigurationSettings.AppSettings["FePicSavePath"].ToString();
string strFePicThumbFormat = ConfigurationSettings.AppSettings["FePicThumbFormat"].ToString().ToLower();
int intFeThumbWidth = Int32.Parse(ConfigurationSettings.AppSettings["FePicThumbWidth"]);
string fileExt;
string strPicTitle = txtboxPicTitle.Text;
string strPicIntro = txtboxPicIntro.Text;
string strPicDate = txtboxPicDate.Text;
int intPicType = Int32.Parse(ddlPicType.SelectedItem.Value);
string strPicType = intPicType.ToString() + "_" + DateTime.Now.Date.ToShortDateString() + "_";
string strFePicWebPath = ConfigurationSettings.AppSettings["FePicWebPath"];
cj168.DataAccess.Admins admins = new cj168.DataAccess.Admins();
//if(admins.FePicTypeSet(textboxTitle.Text,0) < 0)
// lblAddPicInfo.Text = "操作失敗:已經(jīng)存在相同名稱類型,請(qǐng)修改";
//else
// lblAddPicInfo.Text = "操作成功";
StringBuilder picInfo = new StringBuilder();
if(Page.IsValid)
{
for(int i = 0;i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
fileExt = (System.IO.Path.GetExtension(PostedFile.FileName)).ToString().ToLower();
//5-test.jpg
imgNameOnly = strPicType + System.IO.Path.GetFileName(PostedFile.FileName);
if(fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png")
{
if(System.IO.File.Exists(strFePicSavePath + imgNameOnly) && (checkboxlistRewrite.Items[i].Selected == false))
{
erroNumber = erroNumber + 1;
picInfo.Append("<b>錯(cuò)誤:</b>文件("+ (i+1) +") " + imgNameOnly + " 已經(jīng)存在,請(qǐng)修改文件名<br>" );
}
}
else
{
erroNumber = erroNumber + 1;
if(fileExt == "")
picInfo.Append("<b>錯(cuò)誤:</b>請(qǐng)選擇文件<br>" );
else
picInfo.Append("<b>錯(cuò)誤:</b>文件("+ (i+1) +") " + imgNameOnly + " 擴(kuò)展名 " + fileExt + " 不被許可<br>" );
}
}
if(erroNumber > 0)
{
picInfo.Append("<font color=red>全部操作均未完成,請(qǐng)修改錯(cuò)誤,再進(jìn)行操作</font><br>");
hlkOriPic.ImageUrl = "";
hlkOriPic.ToolTip = "";
hlkNewPic.ImageUrl = "";
hlkNewPic.ToolTip = "";
}
else
{
for(int i = 0;i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
imgNameOnly = strPicType + System.IO.Path.GetFileName(PostedFile.FileName);
imgNameNoExt = System.IO.Path.GetFileNameWithoutExtension(PostedFile.FileName);
imgExt = System.IO.Path.GetExtension(PostedFile.FileName).ToString().ToLower();
oriImg = System.Drawing.Image.FromStream(PostedFile.InputStream);
newImg = oriImg.GetThumbnailImage(intFeThumbWidth, intFeThumbWidth * oriImg.Height/oriImg.Width,null,new System.IntPtr(0));
switch(imgExt)
{
//case ".jpeg":
case ".jpg":
oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case ".gif":
oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Gif);
break;
case ".png":
oriImg.Save(strFePicSavePath + imgNameOnly , System.Drawing.Imaging.ImageFormat.Png);
break;
}
//oriImg.Save(ConfigurationSettings.AppSettings["FePicSavePath"] + imgNameNoExt + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
switch(strFePicThumbFormat)
{
//jpeg format can get the smallest file size, and the png is the largest size
//case "jpeg":
case "jpg":
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
imgThumbnail = imgNameOnly + "_thumb.jpg";
break;
case "gif":
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.gif",System.Drawing.Imaging.ImageFormat.Gif);
imgThumbnail = imgNameOnly + "_thumb.gif";
break;
case "png":
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.png",System.Drawing.Imaging.ImageFormat.Png);
imgThumbnail = imgNameOnly + "_thumb.png";
break;
default:
newImg.Save(strFePicSavePath + imgNameOnly + "_thumb.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
imgThumbnail = imgNameOnly + "_thumb.jpg";
break;
}//switch
picInfo.Append("<b>文件 名:</b>" + imgNameOnly + " ( " + oriImg.Width + " x " + oriImg.Height + " ) " + PostedFile.ContentLength/1024 + "KB<br>");
picInfo.Append("<b>縮略圖名:</b>" + imgThumbnail + " ( " + newImg.Width + " x " + newImg.Height + " )<br><br>");
hlkOriPic.ImageUrl = strFePicWebPath + imgNameOnly;
hlkOriPic.ToolTip = "◆原圖◆\n文件名:" + imgNameOnly + "\n尺寸:" + oriImg.Width + " x " + oriImg.Height + "\n字節(jié):" + PostedFile.ContentLength/1024 + "KB";
hlkNewPic.ImageUrl = strFePicWebPath + imgThumbnail;
hlkNewPic.ToolTip = "◆縮略圖◆\n文件名:" + imgThumbnail + "\n尺寸:" + newImg.Width + " x " + newImg.Height;
oriImg.Dispose();
newImg.Dispose();
picInfo.Append("<font color=red>圖片上傳成功</font><br>");
if(admins.FePicDataSet(strPicTitle, strPicDate, imgNameOnly, intPicType, strPicIntro, imgThumbnail,0) < 0)
picInfo.Append("<font color=red>保存信息到數(shù)據(jù)庫(kù)失敗</font><br>");
else
picInfo.Append("<font color=red>保存信息到數(shù)據(jù)庫(kù)成功</font><br>");
}//for
picInfo.Append("<font color=red>所有操作成功</font><br>");
}// if erronumber = 0
}
else
{
picInfo.Append("<font color=red>有錯(cuò)誤,請(qǐng)檢查。操作未成功</font><br>");
hlkOriPic.ImageUrl = "";
hlkOriPic.ToolTip = "";
hlkNewPic.ImageUrl = "";
hlkNewPic.ToolTip = "";
}
for(int i = 0;i < Request.Files.Count; i++)
{
checkboxlistRewrite.Items[i].Selected = false;
}
lblPicInfo.Text = picInfo.ToString();
}
public void CalDateSelected(object sender,System.EventArgs e)
{
txtboxPicDate.Text = calPicDate.SelectedDate.ToShortDateString();
}
public void ServerValidateCheckDate(object sender, System.Web.UI.WebControls.ServerValidateEventArgs value)
{
cj168.util.iUtil iUtils = new cj168.util.iUtil();
if(!iUtils.IsDate(value.Value))
value.IsValid = false;
else
value.IsValid = true;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}