Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //string cid = Request.Params.Keys[0].ToString();
            //string strid = Request.QueryString[cid];

            //string strid = Request.QueryString["imgid"];

            string       strid   = Request.Params["imgid"];
            cSourceImage csimage = new cSourceImage();
            string       imgPath = csimage.GetimgPath(Convert.ToInt32(strid));

            Image1.ImageUrl = imgPath;
        }
        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            cSourceImage csimage = new cSourceImage();

            if (e.CommandName == "del")
            {
                int iimgid = Convert.ToInt32(e.CommandArgument);

                string         DeleteCommand = "DELETE FROM [Image] WHERE [imgid] = @imgid";
                SqlParameter[] par           = new SqlParameter[1];

                int val = -10;
                par[0] = new SqlParameter("@imgid", SqlDbType.Int); par[0].Value = iimgid;
                try
                {
                    //
                    string picPath = csimage.GetimgPath(iimgid);
                    val = csimage.ModiImage(DeleteCommand, par);
                    if (picPath != "")
                    {
                        string savePath = Server.MapPath(picPath); //必须经过这一步操作才能变成有效路径
                        if (System.IO.File.Exists(savePath))       //先判断文件是否存在,再执行操作
                        {
                            System.IO.File.Delete(savePath);
                        }
                    }
                    if (val > 0)
                    {
                        Script.AjaxAlert(DataList1, "恭喜您,图片删除成功!");
                    }

                    //删除之后要重新绑定
                    string drugid = hid_drugid.Value;
                    int    itype  = Convert.ToInt32(DropDownList1.SelectedItem.Value);
                    DataBindText(drugid, itype);
                    CharTextRequired1.TextValue = "";
                }
                catch
                { }
            }
            else if (e.CommandName == "detail")
            {
                //如果是点击原图按钮则要放大图像
                //  Response.Redirect("ResponseImage.aspx", "_blank", "menubar=0,width=200,height=200");
                int gimgid = Convert.ToInt32(e.CommandArgument);

                string str = "<script languge='javascript'> window.open('ResponseImage.aspx?imgid=" + gimgid + "','','height = 600,width = 800,top = 0,left = 0,toobar =no,menubar=no,scrollbars=yes,resizable=yes,location = no,status=no')</script>";
                Response.Write(str);
            }
        }