Exemplo n.º 1
0
 void refreshBtn()
 {
     if (m_isEdit)
     {
         btnAddImage.Text = "保存";
         exitEditBtn.Visible = true;
     }
     else
     {
         btnAddImage.Text = "添加";
         exitEditBtn.Visible = false;
         m_selectImage = null;
         this.descriptionTxt.Text = "";
         this.imagePicUrlTxt.Text = "";
         this.ext1Txt.Text = "";
         this.ext2Txt.Text = "";
         this.ext3Txt.Text = "";
     }
 }
Exemplo n.º 2
0
        private void btnAddImage_Click(object sender, EventArgs e)
        {
            if (m_isEdit)
            {
                if (m_selectImage == null)
                    return;
            }

            string url = MShareDataManager.gInstance.mServerUrl + "AddImage";
            url += "?isEdit=" + m_isEdit;
            Encoding myEncoding = Encoding.GetEncoding("utf-8");
            HttpWebRequest myRequest =
            (HttpWebRequest)WebRequest.Create(url);
            string postData = string.Empty;
            if (m_isEdit)
                postData += "&id=" + idTxt.Text.Trim();
            postData += "&description=" + Util.encode(descriptionTxt.Text.Trim());
            postData += "&imageUrl=" + imagePicUrlTxt.Text.Trim();
            postData += "&isNativePage=" + isNativePageChe.Checked;
            postData += "&redirectUrl=" + redirectUrlTxt.Text.Trim();
            postData += "&ext1=" + ext1Txt.Text.Trim();
            postData += "&ext2=" + ext2Txt.Text.Trim();
            postData += "&ext3=" + ext3Txt.Text.Trim();
            postData += "&width=" + widthTxt.Text.Trim();
            postData += "&height=" + heightTxt.Text.Trim();
            postData += "&categoryId=" +MShareDataManager.gInstance.mCategoryID;
            byte[] data = myEncoding.GetBytes(postData);

            myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();

            // Send the data.
            newStream.Write(data, 0, data.Length);
            newStream.Close();
            WebResponse response = myRequest.GetResponse();
            Stream stream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(stream);
            char[] readByte = new char[response.ContentLength];
            readStream.Read(readByte, 0, (int)response.ContentLength);
            String result = new String(readByte);
            newStream.Close();
            stream.Close();
            switch (Convert.ToInt32(result))
            {
                case 1:
                    requestImageList();
                    break;
                case 2:
                    MessageBox.Show("图片已经存在,无需添加");
                    break;
                case 3:
                    MessageBox.Show("未知错误");
                    break;
            }
            if (imageList != null && imageList.Count > 0)
                m_selectImage =imageList[0];
        }
Exemplo n.º 3
0
        private void newsGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string columnName = imageGridView.Columns[e.ColumnIndex].Name;
            MImage image = imageList[e.RowIndex];
            m_selectImage = image;
            if (m_selectImage == null)
                return;

            if (columnName == "detail")
            {
                this.idTxt.Text = image.mID.ToString();
                this.descriptionTxt.Text = image.mDescription;
                this.imagePicUrlTxt.Text = image.mImageUrl;
                this.ext2Txt.Text = image.mExt2;
                this.ext3Txt.Text = image.mExt3;
                this.ext1Txt.Text = image.mExt1;
                this.widthTxt.Text = image.mWidth.ToString();
                this.heightTxt.Text = image.mHeight.ToString();
                this.isNativePageChe.Checked = image.mIsNativePage;
                this.redirectUrlTxt.Text = image.mRedirectUrl;
                Image img = downloadImg(image.mImageUrl);
                if (img != null)
                {
                    int width = img.Width;
                    int height = img.Height;
                    double rate = (double)height / (double)width;
                    this.imgPic.Width = 120;
                    this.imgPic.SizeMode = PictureBoxSizeMode.Zoom;
                    this.imgPic.Height = Convert.ToInt32(120 * rate);
                    this.imgPic.Image = img;
                }
                m_isEdit = true;
                refreshBtn();
            }
            else if (columnName == "delete")
            {
                HttpWebRequest myRequest =
                       (HttpWebRequest)WebRequest.Create(MShareDataManager.gInstance.mServerUrl + "DeleteImage?id=" + image.mID);
                myRequest.Method = "GET";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                WebResponse response = myRequest.GetResponse();
                Stream stream = response.GetResponseStream();
                StreamReader readStream = new StreamReader(stream);
                char[] readByte = new char[response.ContentLength];
                readStream.Read(readByte, 0, (int)response.ContentLength);
                String result = new String(readByte);
                response.Close();
                stream.Close();
                if (Convert.ToBoolean(result))
                {
                    requestImageList();
                }
            }
        }