调整部分窗体文件名称使之更合理
This commit is contained in:
1 parent
7556b63d10
commit
c66ce84d26
19 files changed
+25
-25
No files matched your search
@@ -0,0 +1,440 @@
|
||||
using AllBase;
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.Result;
|
||||
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.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TemuKJD.Extension;
|
||||
using TemuKJD.KJDForms.BaseForms;
|
||||
using TemuKJD.KJDForms.ShopForms;
|
||||
using Work;
|
||||
|
||||
namespace TemuKJD.KJDForms.ProductThirdSelectForms
|
||||
{
|
||||
public partial class ProductThirdUserSelectForm : BaseForm
|
||||
{
|
||||
bool isInit = false;
|
||||
CheckBox chkSelectAll = null;
|
||||
List<TemuDBProductSelect> lstTemuDBProductSelect = new List<TemuDBProductSelect>();
|
||||
public ProductThirdUserSelectForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void UserSelectThirdProductForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
|
||||
dgvShop.Columns["colSelect"].HeaderText = "";
|
||||
chkSelectAll.Width = chkSelectAll.Height = 13;
|
||||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||||
chkSelectAll.Checked = true;
|
||||
|
||||
this.dgvSelectProduct.AddSelectorColumn("colCheck");
|
||||
this.ucSplitPage1.PageChange += UcSplitPage1_PageChange;
|
||||
}
|
||||
|
||||
private void UcSplitPage1_PageChange(object obj)
|
||||
{
|
||||
SearchDbProdSelect(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
|
||||
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!chkSelectAll.Checked)
|
||||
{
|
||||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||||
{
|
||||
row.Cells["colSelect"].Value = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//var list = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus == "登录成功").Select(ss => ss.ShopId);
|
||||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||||
{
|
||||
//if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
|
||||
row.Cells["colSelect"].Value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnRefreshShop_Click(object sender, EventArgs e)
|
||||
{
|
||||
RefreshShop();
|
||||
}
|
||||
|
||||
private void UserSelectDbProductForm_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (Visible == true)
|
||||
{
|
||||
RefreshShop();
|
||||
|
||||
if (dgvSelectProduct.Rows.Count == 0)
|
||||
SearchDbProdSelect(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshShop()
|
||||
{
|
||||
// 店铺Id
|
||||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||||
// 获取被删除的店铺
|
||||
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> !GlobalConfig.ShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
|
||||
// 更新被删除的店铺列表
|
||||
foreach (var row in dgvRowList)
|
||||
{
|
||||
dgvShop.Rows.Remove(row);
|
||||
}
|
||||
// 绑定其他店铺(含新导入的店铺)
|
||||
foreach (ShopLoginInfo shopEntity in GlobalConfig.ShopLoginList)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(shopEntity.ShopId))
|
||||
BindShop(shopEntity, selectIds);
|
||||
}
|
||||
}
|
||||
|
||||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null)
|
||||
{
|
||||
if (shopEntity == null)
|
||||
return;
|
||||
if (selectShopId == null)
|
||||
selectShopId = new List<string>();
|
||||
|
||||
bool canUse = shopEntity.LoginStatus == "登录成功";
|
||||
canUse = true; // 内部库不需要校验登录状态
|
||||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
|
||||
if (row == null)
|
||||
{
|
||||
this.dgvShop.Rows.Add(
|
||||
!isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse),
|
||||
shopEntity.LoginName,
|
||||
shopEntity.ShopId,
|
||||
shopEntity.ShopAccount,
|
||||
shopEntity.LoginStatus,
|
||||
"选择商品",
|
||||
canUse,
|
||||
shopEntity.AddProductRemaining,
|
||||
string.Empty
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Cells["colSelect"].Value = !isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse);
|
||||
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
|
||||
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
|
||||
row.Cells["colLoginStatus"].Value = shopEntity.LoginStatus;
|
||||
row.Cells["colCanUse"].Value = canUse;
|
||||
row.Cells["colRemaining"].Value = shopEntity.AddProductRemaining;
|
||||
}
|
||||
isInit = false;
|
||||
}
|
||||
|
||||
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||||
return;
|
||||
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
|
||||
string columnName = dgvShop.Columns[e.ColumnIndex].Name;
|
||||
long shopId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToLong();
|
||||
string shopAccount = dgvShop.Rows[e.RowIndex].Cells["colShopName"].Value.ToString();
|
||||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
|
||||
var row = dgvShop.Rows[e.RowIndex];
|
||||
switch (columnName)
|
||||
{
|
||||
case "colSelect":
|
||||
//if (row.Cells["colCanUse"].Value.ParseToBool())
|
||||
{
|
||||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||||
|
||||
chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged;
|
||||
if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
|
||||
chkSelectAll.Checked = true;
|
||||
else
|
||||
chkSelectAll.Checked = false;
|
||||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||||
}
|
||||
//else
|
||||
{
|
||||
//BaseMsgForm.ShowInfo("店铺未登录!");
|
||||
}
|
||||
break;
|
||||
|
||||
case "colSelectProduct": // 认领商品
|
||||
//DbProductListForm dbProductForm = new DbProductListForm(shop);
|
||||
//dbProductForm.ShowDialog();
|
||||
//this.RefreshShop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||||
if (lstShopId.Count == 0)
|
||||
{
|
||||
BaseMsgForm.ShowInfo("请选择店铺!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.ucSplitPage1.CurrentPage != 1)
|
||||
this.ucSplitPage1.CurrentPage = 1;
|
||||
else
|
||||
SearchDbProdSelect(1);
|
||||
}
|
||||
|
||||
public void SearchDbProdSelect(int page)
|
||||
{
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.pbLoading.Visible = true;
|
||||
this.dgvSelectProduct.Rows.Clear();
|
||||
lstTemuDBProductSelect.Clear();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pbLoading.Visible = true;
|
||||
this.dgvSelectProduct.Rows.Clear();
|
||||
lstTemuDBProductSelect.Clear();
|
||||
}
|
||||
Task.Run(() =>
|
||||
{
|
||||
int pageCount;
|
||||
var list = GetSelectProductList(out pageCount, page, 200);
|
||||
lstTemuDBProductSelect.AddRange(list);
|
||||
this.ucSplitPage1.TotalPage = pageCount;
|
||||
|
||||
foreach (var prodSelect in lstTemuDBProductSelect)
|
||||
{
|
||||
Image image = null;
|
||||
string imgUrl = prodSelect?.main_img?.Replace("https", "http");
|
||||
string rst = "";
|
||||
if (!string.IsNullOrWhiteSpace(imgUrl))
|
||||
image = GetHtml.GetUrlImg(imgUrl, out rst);
|
||||
if (!string.IsNullOrEmpty(rst))
|
||||
BaseMsgForm.ShowError(rst);
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
int rowIndex = this.dgvSelectProduct.Rows.Add(
|
||||
false,
|
||||
prodSelect.id,
|
||||
prodSelect.shop_id,
|
||||
prodSelect.shop_account,
|
||||
"进店",
|
||||
"登录",
|
||||
"",//prodSelect.spu_id,
|
||||
"",//prodSelect.skc_id,
|
||||
image,//prod.main_img,
|
||||
prodSelect.product_name,
|
||||
prodSelect.cat_name,
|
||||
prodSelect.ext_code,
|
||||
prodSelect.status,
|
||||
prodSelect.draft_id,
|
||||
"删除");
|
||||
|
||||
dgvSelectProduct.Rows[rowIndex].Height = 60;
|
||||
}));
|
||||
}
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.pbLoading.Visible = false;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public List<TemuDBProductSelect> GetSelectProductList(out int pageCount, int page = 1, int pageSize = 50)
|
||||
{
|
||||
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||||
|
||||
List<TemuDBProductSelect> list = new List<TemuDBProductSelect>();
|
||||
pageCount = 1;
|
||||
|
||||
//第三方库存上传
|
||||
var url = BaseClass.BuildObjString("product_third/get_user_select_product_list");
|
||||
var data = "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
data = UserLogin.GetSignaturex() +
|
||||
"&page=" + page +
|
||||
"&page_size=" + pageSize +
|
||||
//"&out_product_id=" + dbId +
|
||||
//"&shop_id=" + shop.ShopId +
|
||||
//"&shop_account=" + shop.ShopAccount +
|
||||
//"&main_user_name=" + shop.UserName +
|
||||
//"&sub_user_name=" + shop.SubUserName +
|
||||
"&status=" + (cmbStatus.Text == "全部" ? "" : cmbStatus.Text) +
|
||||
"&shop_ids=\"" + string.Join("\",\"", lstShopId) + "\"";
|
||||
}));
|
||||
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);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowError("库存商品查询失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));
|
||||
}));
|
||||
return new List<TemuDBProductSelect>();
|
||||
}
|
||||
|
||||
int count = BaseRegex.GetIntJson(ref html, "count");
|
||||
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
|
||||
pageCount = Math.Max(pageCount, 1);
|
||||
|
||||
var jArr = JObject.Parse(html)["data"];
|
||||
if (jArr.Count() == 0)
|
||||
return list;
|
||||
var sProd = JsonHelper.SerializeObject(jArr);
|
||||
|
||||
try
|
||||
{
|
||||
list = JsonHelper.DeserializeJsonToList<TemuDBProductSelect>(sProd);
|
||||
return list;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new List<TemuDBProductSelect>();
|
||||
}
|
||||
}
|
||||
|
||||
private void dgvSelectProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||||
return;
|
||||
string headerText = dgvSelectProduct.Columns[e.ColumnIndex].HeaderText;
|
||||
var dbId = dgvSelectProduct.Rows[e.RowIndex].Cells["colSelectId"].Value.ParseToString();
|
||||
var dbProduct = lstTemuDBProductSelect.FirstOrDefault(p => p.id.ToString() == dbId);
|
||||
var shopId = dgvSelectProduct.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
|
||||
var draftId = dgvSelectProduct.Rows[e.RowIndex].Cells["colDraftId"].Value.ParseToString();
|
||||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||||
|
||||
switch (headerText)
|
||||
{
|
||||
case "删除":
|
||||
if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
|
||||
return;
|
||||
var rst = DeleteProduct(dbId);
|
||||
if (rst)
|
||||
{
|
||||
SearchDbProdSelect(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
break;
|
||||
case "进店":
|
||||
{
|
||||
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
|
||||
shopLoginForm.InitUrl = "https://seller.kuajingmaihuo.com/goods/product/draft";
|
||||
shopLoginForm.openType = EnumOpenType.manage;
|
||||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||||
shopLoginForm.ShowDialog();
|
||||
}
|
||||
break;
|
||||
case "编辑备注":
|
||||
break;
|
||||
case "草稿箱Id":
|
||||
//if (!string.IsNullOrEmpty(draftId) && shop != null)
|
||||
//{
|
||||
// ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
|
||||
// shopLoginForm.InitUrl = "https://seller.kuajingmaihuo.com/goods/product-create/product-edit?productDraftId=" +
|
||||
// draftId + "&from=productDraftList";
|
||||
// shopLoginForm.openType = EnumOpenType.manage;
|
||||
// shopLoginForm.WindowState = FormWindowState.Maximized;
|
||||
// shopLoginForm.ShowDialog();
|
||||
//}
|
||||
break;
|
||||
case "":
|
||||
dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool DeleteProduct(string dbId)
|
||||
{
|
||||
var url = BaseClass.BuildObjString("product_third/del_select_product");
|
||||
var data = UserLogin.GetSignaturex() +
|
||||
"&db_id=" + dbId;
|
||||
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);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
BaseMsgForm.ShowError("删除商品失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void btnDelSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (BaseMsgForm.ShowConfirm("确定删除选中商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
|
||||
return;
|
||||
|
||||
var DbIdLst = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colSelectId"]?.Value.ToString()).ToList();
|
||||
|
||||
this.pbLoading.Visible = true;
|
||||
this.statusBar.lblTaskStatus.Text = "正在删除...";
|
||||
this.statusBar.pgbTaskProgress.Value = 0;
|
||||
this.statusBar.pgbTaskProgress.Maximum = DbIdLst.Count;
|
||||
this.statusBar.pgbTaskProgress.Text = "0" + "/" + DbIdLst.Count;
|
||||
Task.Run(() =>
|
||||
{
|
||||
foreach (var dbId in DbIdLst)
|
||||
{
|
||||
try
|
||||
{
|
||||
DeleteProduct(dbId);
|
||||
Thread.Sleep(20);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowInfo(ex.Message);
|
||||
}));
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.pgbTaskProgress.Value++;
|
||||
this.statusBar.pgbTaskProgress.Text = this.statusBar.pgbTaskProgress.Value.ToString() + "/" + DbIdLst.Count;
|
||||
}));
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.pgbTaskProgress.Value = DbIdLst.Count;
|
||||
this.statusBar.lblTaskStatus.Text = "删除完成";
|
||||
this.pbLoading.Visible = false;
|
||||
BaseMsgForm.ShowInfo("删除完成!");
|
||||
|
||||
SearchDbProdSelect(this.ucSplitPage1.CurrentPage);
|
||||
}));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user