326 lines
14 KiB
C#
326 lines
14 KiB
C#
using AllBase;
|
||
using AllBase.Model.Param.FissionManage;
|
||
using LittleRabbit.LittleRabbitForms.BaseForms;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Runtime.InteropServices;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||
{
|
||
public partial class CatForm : LRBaseForm
|
||
{
|
||
private const int SB_HORZ = 0;
|
||
private const int SB_VERT = 1;
|
||
private const int SB_CTL = 2;
|
||
private const int SB_BOTH = 3;
|
||
|
||
[DllImport("user32", EntryPoint = "ShowScrollBar")]
|
||
public static extern int ShowScrollBar(int hwnd, int wBar, int bShow);
|
||
|
||
private ProductCollectBase pcb;
|
||
private int iCatId = 0;
|
||
private List<GoodsCategoryModelEx> lstRootGoodsCategory = new List<GoodsCategoryModelEx>();
|
||
private List<GoodsCategoryModelEx> lst2ndGoodsCategory = new List<GoodsCategoryModelEx>();
|
||
private List<GoodsCategoryModelEx> lst3rdGoodsCategory = new List<GoodsCategoryModelEx>();
|
||
public Fission frmFission;
|
||
private int lst1Cid = 0;
|
||
private int lst2Cid = 0;
|
||
private int lst3Cid = 0;
|
||
public CatForm(ProductCollectBase _pcb)
|
||
{
|
||
pcb = _pcb;
|
||
InitializeComponent();
|
||
}
|
||
private void CatForm_Load(object sender, EventArgs e)
|
||
{
|
||
lbxSearch.Height = 300;
|
||
ShowHistoricalCid(pcb.cat_id);
|
||
|
||
//ShowScrollBar((int)this.lvRootCategory.Handle, SB_VERT, 1);
|
||
//ShowScrollBar((int)this.lv2rdCategory.Handle, SB_VERT, 1);
|
||
//ShowScrollBar((int)this.lv3rdCategory.Handle, SB_VERT, 1);
|
||
}
|
||
|
||
private void ShowHistoricalCid(int cid)
|
||
{
|
||
try
|
||
{
|
||
if (Fission.goodsCategoryList.Count == 0)
|
||
Fission.goodsCategoryList = JsonHelper.DeserializeJsonToList<GoodsCategoryModelEx>(AllBase.Model.Param.ProductManage.DyCategoryParam.DyCategorys);
|
||
|
||
lvRootCategory.Clear();
|
||
lstRootGoodsCategory = Fission.goodsCategoryList.FindAll(m => m.parent_id == 0);
|
||
foreach (GoodsCategoryModel item in lstRootGoodsCategory)
|
||
lvRootCategory.Items.Add(item.id.ToString(), item.name, "");
|
||
|
||
List<int> catList = Fission.GetParentCatList(cid);
|
||
string cidName = string.Join(",", catList);
|
||
|
||
if (!string.IsNullOrEmpty(cidName))
|
||
{
|
||
string[] strArrary = cidName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||
strArrary = strArrary.Where(o => o != "0").ToArray();
|
||
if (strArrary.Length == 3)
|
||
{
|
||
lvRootCategory.FocusedItem = lvRootCategory.Items[strArrary[0]];
|
||
lvRootCategory.Items[strArrary[0]].Selected = true;
|
||
lv2rdCategory.FocusedItem = lv2rdCategory.Items[strArrary[1]];
|
||
lv2rdCategory.Items[strArrary[1]].Selected = true;
|
||
lv3rdCategory.Focus();
|
||
lv3rdCategory.FocusedItem = lv3rdCategory.Items[strArrary[2]];
|
||
lv3rdCategory.Items[strArrary[2]].Selected = true;
|
||
}
|
||
else if (strArrary.Length == 2)
|
||
{
|
||
lvRootCategory.FocusedItem = lvRootCategory.Items[strArrary[0]];
|
||
lvRootCategory.Items[strArrary[0]].Selected = true;
|
||
lv2rdCategory.Focus();
|
||
lv2rdCategory.FocusedItem = lv2rdCategory.Items[strArrary[1]];
|
||
lv2rdCategory.Items[strArrary[1]].Selected = true;
|
||
}
|
||
else
|
||
{
|
||
lvRootCategory.Focus();
|
||
lvRootCategory.FocusedItem = lvRootCategory.Items[strArrary[0]];
|
||
if (lvRootCategory.Items[strArrary[0]] != null)
|
||
lvRootCategory.Items[strArrary[0]].Selected = true;
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
private void lvRootCategory_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
lv2rdCategory.Items.Clear();
|
||
lv3rdCategory.Items.Clear();
|
||
lst2Cid = 0;
|
||
lst3Cid = 0;
|
||
var cid = lvRootCategory.FocusedItem.Name;
|
||
lbSelectCatName.Text = "当前选择商品分类:" + lvRootCategory.FocusedItem.Text;
|
||
iCatId = int.Parse(cid);
|
||
lst1Cid = iCatId;
|
||
lst2ndGoodsCategory = Fission.goodsCategoryList.FindAll(m => m.parent_id == iCatId);
|
||
btnChangeCatId.Enabled = lst2ndGoodsCategory.Count == 0;
|
||
foreach (GoodsCategoryModel item in lst2ndGoodsCategory)
|
||
{
|
||
if (item.name.Equals("未知")) continue;
|
||
lv2rdCategory.Items.Add(item.id.ToString(), item.name, "");
|
||
}
|
||
}
|
||
|
||
private void lv2rdCategory_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
lst3Cid = 0;
|
||
lv3rdCategory.Items.Clear();
|
||
var cid = lv2rdCategory.FocusedItem.Name;
|
||
lbSelectCatName.Text = "当前选择商品分类:" + lv2rdCategory.FocusedItem.Text;
|
||
iCatId = int.Parse(cid);
|
||
lst2Cid = iCatId;
|
||
lst3rdGoodsCategory = Fission.goodsCategoryList.FindAll(m => m.parent_id == iCatId);
|
||
btnChangeCatId.Enabled = lst3rdGoodsCategory.Count == 0;
|
||
foreach (GoodsCategoryModel item in lst3rdGoodsCategory)
|
||
{
|
||
if (item.name.Equals("未知")) continue;
|
||
lv3rdCategory.Items.Add(item.id.ToString(), item.name, "");
|
||
}
|
||
}
|
||
|
||
private void lv3rdCategory_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
iCatId = int.Parse(lv3rdCategory.FocusedItem?.Name);
|
||
lst3Cid = iCatId;
|
||
btnChangeCatId.Enabled = true;
|
||
lbSelectCatName.Text = "当前选择商品分类:" + lv3rdCategory.FocusedItem.Text;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 确认变更商品分类
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnChangeCatId_Click(object sender, EventArgs e)
|
||
{
|
||
string sChangedCatName = lbSelectCatName.Text.Split(':')[1];
|
||
if (BaseMsgForm.ShowConfirm("确认商品分类设置为【" + sChangedCatName + "】?").DialogResult.Equals(DialogResult.OK))
|
||
{
|
||
pcb.cat_id = iCatId;
|
||
pcb.cat1 = lst1Cid;
|
||
pcb.main_cid = lst1Cid;
|
||
pcb.cat2 = lst2Cid;
|
||
pcb.cat3 = lst3Cid;
|
||
pcb.cat4 = 0;
|
||
|
||
frmFission.lblCategory.Text = Fission.GetFullCatString(iCatId);
|
||
var cat = Fission.goodsCategoryList.FirstOrDefault(c => c.id == iCatId);
|
||
if (cat != null)
|
||
{
|
||
// {"id":21621,"name":"电吹风","parent_cid":20099,"level":2,"enable":true,"first_cid":20099,"second_cid":21621,"third_cid":0,"fourth_cid":0,"first_name":"个人保健/护理电器","second_name":"电吹风","third_name":"","fourth_name":"","is_leaf":true,"highlight_levels":[],"extra_info":null,"industry_status":0}
|
||
frmFission.fullCatStrings = "[{\"id\":" + cat.id + ",\"name\":\"" + cat.name + "\"," +
|
||
"\"parent_cid\":" + cat.parent_id + ",\"level\":" + cat.level + ",\"enable\":" + cat.enable.ToString().ToLower() + ",";
|
||
List<GoodsCategoryModel> cl = new List<GoodsCategoryModel>();
|
||
cl.Add(cat);
|
||
var catEx = Fission.goodsCategoryList.FirstOrDefault(c => c.id == cat.id);
|
||
var pCat = Fission.goodsCategoryList.FirstOrDefault(c => c.id == cat.parent_id);
|
||
while (pCat != null && pCat.id != 0)
|
||
{
|
||
cl.Insert(0, pCat);
|
||
pCat = Fission.goodsCategoryList.FirstOrDefault(c => c.id == pCat.parent_id);
|
||
}
|
||
while (cl.Count < 4)
|
||
{
|
||
cl.Add(new GoodsCategoryModelEx());
|
||
}
|
||
frmFission.fullCatStrings += "\"first_cid\":" + cl[0].id + ",\"second_cid\":" + cl[1].id + ",\"third_cid\":" + cl[2].id + ",\"fourth_cid\":" + cl[3].id + "," +
|
||
"\"first_name\":\"" + cl[0].name + "\",\"second_name\":\"" + cl[1].name + "\",\"third_name\":\"" + cl[2].name + "\",\"fourth_name\":\"" + cl[3].name + "\",";
|
||
frmFission.fullCatStrings += "\"is_leaf\":" + cat.is_leaf.ToString().ToLower() + ",\"highlight_levels\":[],\"extra_info\":null," +
|
||
"\"industry_status\":" + catEx.industry_status + "}]";
|
||
}
|
||
|
||
Close();
|
||
}
|
||
}
|
||
|
||
private void txtCateSearch_TextChanged(object sender, EventArgs e)
|
||
{
|
||
lbxSearch.Items.Clear();
|
||
if (txtCateSearch.Text.Trim().Length > 0)
|
||
{
|
||
List<string> listResult = new List<string>();
|
||
foreach (var item in Fission.goodsCategoryList)
|
||
{
|
||
if (item.name.Contains(txtCateSearch.Text.Trim()))
|
||
{
|
||
List<string> dd = GetCatString(item.id);
|
||
listResult.AddRange(dd);
|
||
}
|
||
}
|
||
listResult = listResult.Distinct().OrderBy(x => x).ToList();
|
||
|
||
if (listResult.Count > 0)
|
||
{
|
||
lbxSearch.Visible = true;
|
||
foreach (var cstr in listResult)
|
||
lbxSearch.Items.Add(cstr);
|
||
}
|
||
else
|
||
lbxSearch.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
lbxSearch.Visible = false;
|
||
}
|
||
}
|
||
List<string> GetCatString(int cid)
|
||
{
|
||
|
||
//获取上级类目
|
||
List<int> listCat = Fission.GetParentCatList(cid);
|
||
List<string> listParent = new List<string>();
|
||
for (int i = 0; i < listCat.Count; i++)
|
||
{
|
||
var c = Fission.goodsCategoryList.Find(x => x.id == listCat[i]);
|
||
listParent.Add(c.name);
|
||
}
|
||
string strParentList = string.Join(">>", listParent);
|
||
//获取所有下级类目
|
||
List<string> listChild = new List<string>();
|
||
List<int> listChild1 = GetChildCatList(cid);
|
||
for (int i1 = 0; i1 < listChild1.Count; i1++)
|
||
{
|
||
List<int> listChild2 = GetChildCatList(listChild1[i1]);
|
||
string s1 = Fission.goodsCategoryList.Find(x => x.id == listChild1[i1]).name;
|
||
if (listChild2.Count == 0)
|
||
{
|
||
listChild.Add(s1);
|
||
continue;
|
||
}
|
||
for (int i2 = 0; i2 < listChild2.Count; i2++)
|
||
{
|
||
List<int> listChild3 = GetChildCatList(listChild2[i2]);
|
||
string s2 = Fission.goodsCategoryList.Find(x => x.id == listChild2[i2]).name;
|
||
if (listChild3.Count == 0)
|
||
{
|
||
listChild.Add(s1 + ">>" + s2);
|
||
continue;
|
||
}
|
||
for (int i3 = 0; i3 < listChild3.Count; i3++)
|
||
{
|
||
List<int> listChild4 = GetChildCatList(listChild3[i3]);
|
||
string s3 = Fission.goodsCategoryList.Find(x => x.id == listChild3[i3]).name;
|
||
if (listChild4.Count == 0)
|
||
{
|
||
listChild.Add(s1 + ">>" + s2 + ">>" + s3);
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
List<string> listResult = new List<string>();
|
||
if (listChild.Count > 0)
|
||
{
|
||
for (int i = 0; i < listChild.Count; i++)
|
||
{
|
||
listResult.Add(strParentList + ">>" + listChild[i]);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
listResult.Add(strParentList);
|
||
}
|
||
return listResult;
|
||
}
|
||
List<int> GetChildCatList(int cid)
|
||
{
|
||
List<int> list = new List<int>();
|
||
var listNext = Fission.goodsCategoryList.FindAll(x => x.parent_id == cid);
|
||
for (int i = 0; i < listNext.Count; i++)
|
||
list.Add(listNext[i].id);
|
||
return list;
|
||
}
|
||
|
||
private void lbxSearch_Click(object sender, EventArgs e)
|
||
{
|
||
if (lbxSearch.SelectedIndex >= 0)
|
||
{
|
||
string cateStr = lbxSearch.SelectedItem.ToString();
|
||
string[] cateArr = cateStr.Split(new string[] { ">>" }, StringSplitOptions.RemoveEmptyEntries);
|
||
|
||
GoodsCategoryModel model = null;
|
||
if (cateArr.Length > 0)
|
||
model = Fission.goodsCategoryList.Find(x => x.parent_id == 0 && x.name == cateArr[0]);
|
||
|
||
if (cateArr.Length > 1 && model != null)
|
||
{
|
||
model = Fission.goodsCategoryList.Find(x => x.parent_id == model.id && x.name == cateArr[1]);
|
||
}
|
||
if (cateArr.Length > 2 && model != null)
|
||
{
|
||
model = Fission.goodsCategoryList.Find(x => x.parent_id == model.id && x.name == cateArr[2]);
|
||
}
|
||
if (cateArr.Length > 3 && model != null)
|
||
{
|
||
model = Fission.goodsCategoryList.Find(x => x.parent_id == model.id && x.name == cateArr[3]);
|
||
}
|
||
if (model != null)
|
||
ShowHistoricalCid(model.id);
|
||
}
|
||
lbxSearch.Visible = false;
|
||
}
|
||
}
|
||
}
|