456 lines
19 KiB
C#
456 lines
19 KiB
C#
using AllBase;
|
||
using AllBase.Model.Param.TemuProductManage;
|
||
using AllBase.Model.Result;
|
||
using NaiBa.Util;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Globalization;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Security.Policy;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.BLL;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.WXForms.ShopForms;
|
||
using Work;
|
||
|
||
namespace TemuKJD.WXForms.AdminForms
|
||
{
|
||
public partial class WXAdminQualificationImageForm : BaseGeneralForm
|
||
{
|
||
static WXAdminQualificationImageForm inst = null;
|
||
public static WXAdminQualificationImageForm Instance
|
||
{
|
||
get { if (inst == null) inst = new WXAdminQualificationImageForm(); return inst; }
|
||
set { inst = value; }
|
||
}
|
||
public static ConcurrentList<ShopLoginInfo> lstAdminShopInfo { get; set; } = new ConcurrentList<ShopLoginInfo>();
|
||
|
||
public WXAdminQualificationImageForm()
|
||
{
|
||
InitializeComponent();
|
||
|
||
Instance = this;
|
||
}
|
||
|
||
private void AdminShopForm_Load(object sender, EventArgs e)
|
||
{
|
||
this.ucSplitPage1.PageChange += UcSplitPage1_PageChange;
|
||
this.dgvShop.AddSelectorColumn("colSelect");
|
||
}
|
||
|
||
bool firstLoad = true;
|
||
private void AdminShopForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (this.Visible == true && firstLoad)
|
||
{
|
||
firstLoad = false;
|
||
this.pbLoading.Visible = true;
|
||
SearchImg(this.ucSplitPage1.CurrentPage);
|
||
}
|
||
}
|
||
|
||
private void UcSplitPage1_PageChange(object obj)
|
||
{
|
||
SearchImg(this.ucSplitPage1.CurrentPage);
|
||
}
|
||
|
||
public void SearchImg(int page)
|
||
{
|
||
List<string> shopIdList = GetCheckedShopIdList();
|
||
if (InvokeRequired)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.dgvShop.Rows.Clear();
|
||
lstAdminShopInfo.Clear();
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.dgvShop.Rows.Clear();
|
||
lstAdminShopInfo.Clear();
|
||
}
|
||
Task.Run(() =>
|
||
{
|
||
int pageCount;
|
||
decimal seconds = 0;
|
||
var list = AdminGetServerQualificationImageLst(out pageCount, out seconds, page, ucSplitPage1.PageSize);
|
||
lstAdminShopInfo.AddRange(list);
|
||
this.ucSplitPage1.TotalPage = pageCount;
|
||
|
||
foreach (var shop in lstAdminShopInfo)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
int rowIndex = this.dgvShop.Rows.Add(
|
||
shopIdList.Contains(shop.ShopId + shop.UserName),
|
||
shop.LoginName,
|
||
shop.ShopId,
|
||
shop.ShopAccount,
|
||
shop.Notes,
|
||
shop.GroupName,
|
||
"-",
|
||
shop.AddProductRemaining,
|
||
"+",
|
||
//"±",
|
||
shop.Cookies,
|
||
shop.UserName,
|
||
shop.SubUserName,
|
||
shop.UploadAccount,
|
||
shop.BuyAccount,
|
||
shop.ChatAccount,
|
||
"",
|
||
"进入",
|
||
"检测",
|
||
string.IsNullOrWhiteSpace(shop.LoginStatus) ? "未登录" : shop.LoginStatus.Trim(),
|
||
string.IsNullOrWhiteSpace(shop.LoginStatus2) ? "国际版未登录" : shop.LoginStatus2.Trim(),
|
||
"购买",
|
||
"多重登录",
|
||
shop.ApiAuthStatus,
|
||
shop.BuyApiAuth.ApiAuthStatus,
|
||
"导入Cookie",
|
||
"复制Cookie",
|
||
"上传",
|
||
shop.OperateSubSaName,
|
||
"编辑",
|
||
"删除");
|
||
}));
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = false;
|
||
this.statusBar.lblTaskStatus.Text = "店铺查询完毕";
|
||
#if DEBUG
|
||
this.statusBar.lblTaskStatus.Text += ",耗时:" + seconds;
|
||
#endif
|
||
}));
|
||
});
|
||
}
|
||
|
||
private void btnSearch_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.ucSplitPage1.CurrentPage != 1)
|
||
this.ucSplitPage1.CurrentPage = 1;
|
||
else
|
||
SearchImg(1);
|
||
}
|
||
|
||
private void pnlEmpty_Click(object sender, EventArgs e)
|
||
{
|
||
this.txtCatName.Text = "";
|
||
}
|
||
|
||
bool IsOperate { get; set; } = false;
|
||
|
||
private void shopLoginForm_SaveComplete(object obj)
|
||
{
|
||
SearchImg(this.ucSplitPage1.CurrentPage);
|
||
}
|
||
|
||
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
|
||
|
||
switch (headerText)
|
||
{
|
||
case "进入店铺":
|
||
//IsOperate = true;
|
||
//{
|
||
// WXAdminShopLoginForm adminLoginForm = new WXAdminShopLoginForm(shop);
|
||
// adminLoginForm.openType = EnumOpenType.manage;
|
||
// adminLoginForm.WindowState = FormWindowState.Maximized;
|
||
// adminLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home";
|
||
// adminLoginForm.Show();
|
||
//}
|
||
//IsOperate = false;
|
||
break;
|
||
case "删除":
|
||
if (BaseMsgForm.ShowConfirm("确定删除吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
|
||
return;
|
||
//if (ShopBLL.AdminDelServerShop(shop))
|
||
// SearchImg(this.ucSplitPage1.CurrentPage);
|
||
break;
|
||
case "更改图片":
|
||
IsOperate = true;
|
||
{
|
||
//UploadProduct(shop);
|
||
}
|
||
IsOperate = false;
|
||
break;
|
||
case "":
|
||
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private List<string> GetCheckedShopIdList()
|
||
{
|
||
List<string> shopNameList = new List<string>();
|
||
for (int i = 0; i < dgvShop.Rows.Count; i++)
|
||
{
|
||
if (dgvShop.Rows[i].Cells["colSelect"].Value.ParseToBool())
|
||
{
|
||
string shopName = dgvShop.Rows[i].Cells["colShopId"].Value.ParseToString();
|
||
shopName += dgvShop.Rows[i].Cells["colUser"].Value.ParseToString();
|
||
shopNameList.Add(shopName);
|
||
}
|
||
}
|
||
return shopNameList;
|
||
}
|
||
|
||
public List<ShopLoginInfo> AdminGetServerQualificationImageLst(out int pageCount, out decimal seconds, int page = 1, int pageSize = 50)
|
||
{
|
||
List<ShopLoginInfo> list = new List<ShopLoginInfo>();
|
||
pageCount = 1;
|
||
seconds = 0;
|
||
|
||
var url = BaseClass.BuildObjString("shop/admin_get_server_qualification_image_list");
|
||
var data = UserLogin.GetSignaturex() +
|
||
"&page=" + page +
|
||
"&page_size=" + pageSize +
|
||
"&search_cat_name=" + txtCatName.Text.Trim();
|
||
if (BaseClass.SaLevel > 1)
|
||
data += "&operate_sub_sa_name=" + BaseClass.UserName;
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html)
|
||
|| !html.Contains("shop_id") || !html.Contains("shop_account") || !html.Contains("login_pass"))
|
||
{
|
||
return list;
|
||
}
|
||
|
||
int count = BaseRegex.GetIntJson(ref html, "count");
|
||
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
|
||
pageCount = Math.Max(pageCount, 1);
|
||
seconds = BaseRegex.GetDecimalJson(ref html, "seconds");
|
||
|
||
return ShopBLL.DeserializationShop(html);
|
||
}
|
||
|
||
private void dgvShop_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
|
||
{
|
||
}
|
||
|
||
public static Image EmptyImage = null;
|
||
|
||
private void btnUploadImg_Click(object sender, EventArgs e)
|
||
{
|
||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||
openFileDialog.Multiselect = false;
|
||
// 设置过滤条件,只显示文本文件
|
||
openFileDialog.Filter = "图片文件 (*.jpeg;*.jpg;*.png)|*.jpeg;*.jpg;*.png|All files (*.*)|*.*";
|
||
// 显示对话框并获取结果
|
||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
try
|
||
{
|
||
string filePath = openFileDialog.FileName;
|
||
Image imageSource = Image.FromFile(filePath);
|
||
EmptyImage = new Bitmap(900, 1200);
|
||
using (Graphics g = Graphics.FromImage(EmptyImage))
|
||
{
|
||
g.DrawImage(imageSource, new Rectangle(0, 0, EmptyImage.Width, EmptyImage.Height), 0, 0, imageSource.Width, imageSource.Height, GraphicsUnit.Pixel);
|
||
}
|
||
|
||
string imgBase64 = "";
|
||
using (MemoryStream memoryStream = new MemoryStream())
|
||
{
|
||
EmptyImage.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
byte[] imageBytes = memoryStream.ToArray();
|
||
imgBase64 = Convert.ToBase64String(imageBytes);
|
||
}
|
||
|
||
if (this.pictureBox1.Tag.ParseToString() != imgBase64)
|
||
{
|
||
this.pictureBox1.Tag = imgBase64;
|
||
this.pictureBox1.ImageLocation = "";
|
||
|
||
Image image = new Bitmap(900, 1200);
|
||
using (Graphics g = Graphics.FromImage(image))
|
||
{
|
||
g.DrawImage(EmptyImage, new Rectangle(0, 0, image.Width, image.Height), 0, 0, EmptyImage.Width, EmptyImage.Height, GraphicsUnit.Pixel);
|
||
}
|
||
DrawText(image, txtLeft.Text.ParseToInt(), txtTop.Text.ParseToInt(), txtRight.Text.ParseToInt(), txtBottom.Text.ParseToInt());
|
||
this.pictureBox1.Image = image;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseMsgForm.ShowError("打开自定义sku图片失败 " + ex.Message);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
public static void DrawText(Image img, int _txtLeft, int _txtTop, int _txtRight, int _txtBottom)
|
||
{
|
||
if (img == null)
|
||
return;
|
||
|
||
string bookName = "行走中国 : 人文风情和自然生态发现之旅";
|
||
string author = "雷东军";
|
||
string publisher = "中国工人出版社";
|
||
string isbn = "978-7-500-87761-5";
|
||
string binding = "装 帧:平装";
|
||
string edition = "版 次:1";
|
||
string publishTime = "2021-12-01";
|
||
string bookPrice = "37.39";
|
||
|
||
var bookImg = img;
|
||
var imgH = bookImg.Height;
|
||
var imgW = bookImg.Width;
|
||
using (Graphics g = Graphics.FromImage(bookImg))
|
||
{
|
||
Brush textBrush = Brushes.Black;
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||
float txtTop = _txtTop;
|
||
float txtBottom = _txtBottom;
|
||
float txtLeft = _txtLeft;
|
||
float txtRight = _txtRight;
|
||
int txtWidth = (int)imgW - (int)txtLeft - (int)txtRight; // 370;
|
||
|
||
// 书名
|
||
Font font = new Font("宋体", 22, FontStyle.Bold);
|
||
RectangleF rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(bookName.Replace("图书名称:", ""), font, textBrush, rectF);
|
||
// 测量文本的高度 决定接下来文字绘制位置
|
||
var textSize = g.MeasureString(bookName.Replace("图书名称:", ""), font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
font = new Font("宋体", 15, FontStyle.Bold);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(author.Replace("作 者:", "").TrimEnd('著', ' ') + " 著", font, textBrush, rectF);
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(author.Replace("作 者:", "").TrimEnd('著', ' ') + " 著", font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(publisher.Replace("出版发行:", ""), font, textBrush, rectF);
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(publisher.Replace("出版发行:", ""), font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(isbn.Replace("ISBN/CN刊号:", "ISBN "), font, textBrush, rectF);
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "ISBN "), font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
// 以下从下往上写
|
||
txtTop = imgH - txtBottom;
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(binding, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(binding, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(edition, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(edition, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(publishTime, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(publishTime, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(author, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(author, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(bookPrice + "元", font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(bookPrice + "元", font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(bookName, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(bookName, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "书 号:ISBN "), font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(isbn.Replace("ISBN/CN刊号:", "书 号:ISBN "), font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(publisher, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(publisher, font, textBrush, rectF);
|
||
|
||
}
|
||
}
|
||
|
||
private void txt_TextChanged(object sender, EventArgs e)
|
||
{
|
||
Image image = new Bitmap(900, 1200);
|
||
using (Graphics g = Graphics.FromImage(image))
|
||
{
|
||
g.DrawImage(EmptyImage, new Rectangle(0, 0, image.Width, image.Height), 0, 0, EmptyImage.Width, EmptyImage.Height, GraphicsUnit.Pixel);
|
||
}
|
||
DrawText(image, txtLeft.Text.ParseToInt(), txtTop.Text.ParseToInt(), txtRight.Text.ParseToInt(), txtBottom.Text.ParseToInt());
|
||
this.pictureBox1.Image = image;
|
||
}
|
||
|
||
private void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (pictureBox1.Tag.ParseToString().IsNullOrEmpty())
|
||
return;
|
||
|
||
var thumbImage = new Bitmap(90, 120);
|
||
using (Graphics g = Graphics.FromImage(thumbImage))
|
||
{
|
||
g.DrawImage(EmptyImage, new Rectangle(0, 0, thumbImage.Width, thumbImage.Height), 0, 0, EmptyImage.Width, EmptyImage.Height, GraphicsUnit.Pixel);
|
||
}
|
||
|
||
string thumbBase64 = "";
|
||
using (MemoryStream memoryStream = new MemoryStream())
|
||
{
|
||
thumbImage.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
byte[] imageBytes = memoryStream.ToArray();
|
||
thumbBase64 = Convert.ToBase64String(imageBytes);
|
||
}
|
||
|
||
var url = BaseClass.BuildWXObjString("product/wx_add_mdy_qualification_image");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&img_md5=" + BaseClass.GetMd5(pictureBox1.Tag.ParseToString());
|
||
data += "&img_base64=" + pictureBox1.Tag.ParseToString();
|
||
data += "&txt_margin=" + txtLeft.Text.ParseToInt() + "," + txtTop.Text.ParseToInt() + "," + txtRight.Text.ParseToInt() + "," + txtBottom.Text.ParseToInt();
|
||
data += "&img_thumb_base64=" + thumbBase64;
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
}
|
||
}
|
||
}
|