• 上传图象,略缩


    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using NetBar_Info;
    using System.IO;
    namespace kmmWeb.nutrition
    {
     /// <summary>
     /// NutAdd 的摘要说明。
     /// </summary>
     public class NutAdd : System.Web.UI.Page
     {
      protected System.Web.UI.WebControls.Button BAdd;
      protected System.Web.UI.WebControls.Label id;
      protected System.Web.UI.WebControls.Label userid;
      protected System.Web.UI.WebControls.Label hit;
      protected System.Web.UI.WebControls.TextBox Name;
      protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
      protected System.Web.UI.WebControls.DropDownList Sex;
      protected System.Web.UI.WebControls.Label shen;
      protected System.Web.UI.WebControls.Label shi;
      protected System.Web.UI.WebControls.Label qu;
      protected System.Web.UI.WebControls.TextBox Address;
      protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
      protected System.Web.UI.WebControls.TextBox Tel;
      protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
      protected System.Web.UI.WebControls.TextBox QQ;
      protected System.Web.UI.WebControls.TextBox Email;
      protected System.Web.UI.WebControls.TextBox SfzNum;
      protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
      protected System.Web.UI.WebControls.DropDownList PxjgID;
      protected System.Web.UI.WebControls.TextBox ZsNum;
      protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
      protected System.Web.UI.WebControls.TextBox Textbox1;
      protected System.Web.UI.WebControls.DropDownList DropDownList1;
      protected System.Web.UI.WebControls.Label regtime;
      protected System.Web.UI.HtmlControls.HtmlSelect province;
      protected System.Web.UI.HtmlControls.HtmlSelect city;
      protected System.Web.UI.WebControls.ImageButton ImageButton1;
      protected System.Web.UI.HtmlControls.HtmlInputFile file1;
      protected System.Web.UI.HtmlControls.HtmlSelect county;
     
      private void Page_Load(object sender, System.EventArgs e)
      {
    //   if(Session["UserId"]!=null && Session["UserName"]!=null)
    //   {
        bindpxjg();
        bind();
    //   }
    //   else
    //   {
    //    Response.Write("<Script>alert('请重新登陆!'); location='../index.aspx';</Script>");
    //   }
       
      }

      #region Web 窗体设计器生成的代码
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {   
       this.BAdd.Click += new System.EventHandler(this.BAdd_Click);
       this.Load += new System.EventHandler(this.Page_Load);

      }
      #endregion

      public void bindpxjg()
      {
       Mz.BLL.Organ bll=new Mz.BLL.Organ();
       DataSet ds=bll.GetList();
       for(int i=0;i<ds.Tables[0].Rows.Count;i++)
       {
        PxjgID.Items.Add(ds.Tables[0].Rows[i]["PxjgName"].ToString());
       }
      }

      public void bind()
      {
       try
       {
        Mz.BLL.Nutrition bll=new Mz.BLL.Nutrition();
    //    DataSet dss=MZ.Common.Data.DbHelperSQL.Query("select id from Nutrition where UserID='"+Session["UserId"].ToString()+"'");
    //    Mz.Model.Nutrition model=bll.GetModel(int.Parse(dss.Tables[0].Rows[0]["id"].ToString()));
        Mz.Model.Nutrition model=bll.GetModel(5);
        id.Text=model.id.ToString();
        userid.Text=model.UserID.ToString();;
        Name.Text=model.Name;
        Sex.SelectedItem.Text=model.Sex;
        shen.Text=model.Shen;
        shi.Text=model.Shi;
        qu.Text=model.Qu;
        Address.Text=model.Address ;
        QQ.Text=model.QQ;
        Email.Text=model.Email;
        Tel.Text=model.Tel;
        SfzNum.Text=model.SfzNum;
        ZsNum.Text=model.ZsNum;
        hit.Text=model.Hit.ToString();
        PxjgID.SelectedItem.Text=model.Pxjg;
        Textbox1.Text=model.Fwrs.ToString();
        DropDownList1.SelectedItem.Text=model.Shqx;
        regtime.Text=model.reg_time.ToString();
        ImageButton1.ImageUrl="img/file/"+model.bz;
        file1.Value=model.bz;
       }
       catch{}
      }

      private void BAdd_Click(object sender, System.EventArgs e)
      {
       try
       {
        Mz.BLL.Nutrition bll=new Mz.BLL.Nutrition();
        Mz.Model.Nutrition model=new Mz.Model.Nutrition();
        model.id=int.Parse(id.Text.Trim());
        model.UserID=int.Parse(userid.Text.Trim());
        model.Name=Name.Text;
        model.Sex=Sex.SelectedItem.Text;
        if(Request.Form["province"].ToString().Trim()=="省份" && Request.Form["city"].ToString().Trim()=="地级市" && Request.Form["county"].ToString().Trim()=="市、县级市、县")
        {
         model.Shen=shen.Text.Trim();
         model.Shi=shi.Text.Trim();
         model.Qu=qu.Text.Trim();
        }
        else
        {
         model.Shen=Request.Form["province"].ToString();
         model.Shi=Request.Form["city"].ToString();
         model.Qu=Request.Form["county"].ToString(); 
        }
        model.Address=Address.Text;
        model.QQ=QQ.Text;
        model.Email=Email.Text;
        model.Tel=Tel.Text;
        model.SfzNum=SfzNum.Text;
        model.ZsNum=ZsNum.Text;
        model.Pxjg=PxjgID.SelectedItem.Text;
        model.Fwrs=int.Parse(Textbox1.Text.Trim());
        model.Shqx=DropDownList1.SelectedItem.Text;
        model.reg_time=DateTime.Parse(regtime.Text.Trim());
        model.Hit=int.Parse(hit.Text.Trim());

       
        //string PicUrl="";
        string  smallUrl="";
        string postName=file1.PostedFile.FileName;
        if(postName=="")
        {
         model.bz=file1.Value;
        }
        else
        {
         try
         {   
        
          string uploadfile = Server.MapPath("img/file/");
          string uploadFileName =postName.Substring(postName.LastIndexOf(".")+1);//取出扩展名
          string guidString = DateTime.Now.ToString("ddmmmss");
          string guidString1 = "small"+guidString;
          string picPath = uploadfile + @"\" + guidString + ".jpg";
          string picPath1 = uploadfile + @"\" + guidString1 + ".jpg";

          //判断图片大小
          if ((file1.PostedFile.ContentLength > 0) && (file1.PostedFile.ContentLength < 2048000) && ((uploadFileName.ToLower() == "gif") || (uploadFileName.ToLower() == "jpg") || (uploadFileName.ToLower() == "png") || (uploadFileName.ToLower() == "bmp")))
          {
           file1.PostedFile.SaveAs(picPath);
           ThumbnailImage Img = new ThumbnailImage();
           string Url = "img/file/" + guidString + ".jpg";
           smallUrl=Img.BuildThumbnailImageNew("small", Url, "img/file/", 140, 100);
                         //File.Delete(Url);
          }
          else
          {
           Response.Write("<Script language=javascript>alert('非常抱歉您的图片大小已经超出范围!');</Script>");
           return ;
          }
         // smallUrl = guidString + ".jpg";
         }
         catch
         {
          Response.Write("<Script language=javascript>alert('非常抱歉您的图片大小已经超出范围!');</Script>");
          return;
         }
         //SourceImagePath.Substring(SourceImagePath.LastIndexOf(".")).ToLower();
         model.bz=smallUrl.Trim().Substring(smallUrl.Trim().LastIndexOf("/")+1).ToLower();

        }
        if(bll.Update(model)>0)
        {
         Response.Write("<Script>alert('修改成功!');</Script>");
         bind();
        }
        else
        {
         Response.Write("<Script>alert('非常抱歉,您没有修改成功!');</Script>");
         return;
        }
       }
       catch{}
      }


     
     }
    }

    噢耶游戏是中国最大的轻社交游戏开发商,致力于手机页游的研发及推广业务。我们首创性地提出了HTML5游戏中心思路,在第三方App 中嵌入式休闲游戏,为开发者提供了全新的应用内游戏解决方案。
  • 相关阅读:
    orm操作
    模板语言
    路由
    newlib中printf库函数的实现
    调试问题记录
    GCC部分编译选项解析
    Lauterbach TRACE32使用技巧记录
    ARM32 页表映射过程
    TTBR0与TTBR1
    Camera Sensor基础知识
  • 原文地址:https://www.cnblogs.com/yintian2/p/766320.html
Copyright © 2020-2023  润新知