protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request.QueryString["id"] != "" && Request.QueryString["id"] != null)
         {
             int id = Convert.ToInt32(Request.QueryString["id"]);
             mod = BiaoShiImgBLL.GetmodByid(id);
             if (mod != null)
             {
                 txtbiaoshiNo.Text = mod.BiaoShiNo;
                 if (mod.BiaoShiImg != "")
                 {
                     imgguanJiaoZhenImg.ImageUrl = mod.BiaoShiImg;
                 }
                 else
                 {
                     imgguanJiaoZhenImg.ImageUrl = "/images/nophoto.jpg";
                 }
             }
             imgguanJiaoZhenImg.Visible = true;
             txtbiaoshiNo.Enabled = false;
         }
         else
         {
             imgguanJiaoZhenImg.Visible = false;
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 根据主键id查询信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BiaoShiImgMOD GetmodByid(int id)
        {
            BiaoShiImgMOD mod = new BiaoShiImgMOD();
            string sqlcommandString = "select * from BiaoShiImg where imgId=" + id;

            try
            {
                SqlDataReader reader = SqlHelper.ExecuteReader(sqlcommandString);
                if (reader.Read())
                {
                    mod.ImgId = Convert.ToInt32(reader["ImgId"].ToString());
                    mod.BiaoShiNo = reader["BiaoShiNo"].ToString();
                    mod.BiaoShiImg = reader["BiaoShiImg"].ToString();

                }
                reader.Close();
                return mod;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Save_Click(object sender, ImageClickEventArgs e)
        {
            int num = 0;

            if (Request.QueryString["id"] != "" && Request.QueryString["id"] != null)
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                mod = BiaoShiImgBLL.GetmodByid(id);
                Boolean fileOK = false;
                //上传外形图纸
                if (fuguanJiaoZhenImg.HasFile)
                {
                    // 得到文件的后缀
                    String fileExtension =
                        System.IO.Path.GetExtension(fuguanJiaoZhenImg.FileName).ToLower();
                    // 允许的文件后缀
                    String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                    // 看包含的文件是否是被允许的文件后缀
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            // 如果是,标志位置为真
                            fileOK = true;
                        }
                    }

                    if (fileOK)
                    {
                        string url = "~/fileUpload/biaoshi_" + mod.BiaoShiNo+fileExtension;

                        if (fuguanJiaoZhenImg.HasFile)
                        {
                            string fileType = fuguanJiaoZhenImg.PostedFile.ContentType;

                            string name = fuguanJiaoZhenImg.PostedFile.FileName;  //文件路径
                            FileInfo fileInfo = new FileInfo(name);
                            try
                            {
                                fuguanJiaoZhenImg.SaveAs(Server.MapPath(url));
                                mod.BiaoShiImg = url;
                                fileOK = false;

                            }
                            catch (Exception ex)
                            {
                                Response.Write("<script>alert('上传有误,请重新上传!');</script>");
                            }
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('只能上传gif,png,jpeg,jpg格式的文件!');</script>");
                        return;
                    }
                }

                num = BiaoShiImgBLL.Updatemod(mod);
            }
            else
            {
                mod = new BiaoShiImgMOD();
                mod.BiaoShiNo = txtbiaoshiNo.Text.Trim();
                Boolean fileOK = false;
                //上传外形图纸
                if (fuguanJiaoZhenImg.HasFile)
                {
                    // 得到文件的后缀
                    String fileExtension =
                        System.IO.Path.GetExtension(fuguanJiaoZhenImg.FileName).ToLower();
                    // 允许的文件后缀
                    String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                    // 看包含的文件是否是被允许的文件后缀
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            // 如果是,标志位置为真
                            fileOK = true;
                        }
                    }

                    if (fileOK)
                    {
                        string url = "~/fileUpload/biaoshi_" + mod.BiaoShiNo + fileExtension;

                        if (fuguanJiaoZhenImg.HasFile)
                        {
                            string fileType = fuguanJiaoZhenImg.PostedFile.ContentType;

                            string name = fuguanJiaoZhenImg.PostedFile.FileName;  //文件路径
                            FileInfo fileInfo = new FileInfo(name);
                            try
                            {
                                fuguanJiaoZhenImg.SaveAs(Server.MapPath(url));
                                mod.BiaoShiImg = url;
                                fileOK = false;

                            }
                            catch (Exception ex)
                            {
                                Response.Write("<script>alert('上传有误,请重新上传!');</script>");
                            }
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('只能上传gif,png,jpeg,jpg格式的文件!');</script>");
                        return;
                    }
                }
                else
                {
                    mod.BiaoShiImg = "";
                }

                num = BiaoShiImgBLL.Insertmod(mod);
            }
            if (num > 0)
            {
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "ListArea", "DetailsPageControl.CloseBox();alert('提交成功');DetailsPageControl.ReflushList('ProductManage/BiaoShiImageManage.aspx');", true);
            }
            else if(num==0)
            {
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "ListArea", "alert('提交失败');", true);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="dtomodList">数据对象</param>
 /// <returns></returns>
 public static int Updatemod(BiaoShiImgMOD mod)
 {
     return BiaoShiImgDAO.Updatemod(mod);
 }
Beispiel #5
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="dtomodList">对象</param>
 /// <returns></returns>
 public static int Insertmod(BiaoShiImgMOD mod)
 {
     return BiaoShiImgDAO.Insertmod(mod);
 }
Beispiel #6
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="dtomodList">数据对象</param>
 /// <returns></returns>
 public static int Updatemod(BiaoShiImgMOD mod)
 {
     string sqlCommandString = "Update BiaoShiImg Set BiaoShiImg=@BiaoShiImg Where imgId=@imgId";
     SqlParameter[] arParams = new SqlParameter[2];
     arParams[0] = new SqlParameter("@imgId", mod.ImgId);
     arParams[1] = new SqlParameter("@BiaoShiImg", mod.BiaoShiImg);
     return SqlHelper.ExecuteNonQuery(CommandType.Text, sqlCommandString, arParams);
 }
Beispiel #7
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dtomodList">对象</param>
        /// <returns></returns>
        public static int Insertmod(BiaoShiImgMOD mod)
        {
            string sqlCommandString = string.Format(
            @"IF not exists(select 1 from BiaoShiImg where BiaoShiNo='{0}')
                 BEGIN
                 Insert Into BiaoShiImg(BiaoShiNo,BiaoShiImg) Values (@BiaoShiNo,@BiaoShiImg)
                 END ",mod.BiaoShiNo);
            SqlParameter[] arParams = new SqlParameter[2];
            arParams[0] = new SqlParameter("@BiaoShiNo", mod.BiaoShiNo);
            arParams[1] = new SqlParameter("@BiaoShiImg", mod.BiaoShiImg);

            return SqlHelper.ExecuteNonQuery(CommandType.Text, sqlCommandString, arParams);
        }