171 lines
6.7 KiB
C#
171 lines
6.7 KiB
C#
using AllBase;
|
|
using AllBase.Model.Result;
|
|
using LittleRabbit.LittleRabbitForms.BaseForms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Work;
|
|
|
|
namespace LittleRabbit.LittleRabbitForms.ShopForms
|
|
{
|
|
public partial class SubAccountShopEditForm : LRBaseForm
|
|
{
|
|
DouShopLoginInfo shop = null;
|
|
public List<DouShopSubAccountInfo> AllSubAccountList { get; set; } = new List<DouShopSubAccountInfo>();
|
|
public List<DouShopSubAccountInfo> ShopSubAccountList { get; set; } = new List<DouShopSubAccountInfo>();
|
|
public List<DouShopSubAccountInfo> NotShopSubAccountList { get; set; } = new List<DouShopSubAccountInfo>();
|
|
public SubAccountShopEditForm(DouShopLoginInfo _shop)
|
|
{
|
|
InitializeComponent();
|
|
shop = _shop;
|
|
}
|
|
|
|
private void SubAccountShopEditForm_Load(object sender, EventArgs e)
|
|
{
|
|
this.TitleText = "店铺 " + shop?.ShopAccount + " 子账号编辑";
|
|
label1.Text = "店铺 " + shop?.ShopAccount + " 子账号";
|
|
label2.Text = "未分配的子账号";
|
|
|
|
GetUser();
|
|
}
|
|
|
|
private void GetUser()
|
|
{
|
|
flpNotSubAccount.Controls.Clear();
|
|
flpShopSubAccount.Controls.Clear();
|
|
AllSubAccountList.Clear();
|
|
string url = BaseClass.BuildObjString("user&act=get");
|
|
string data = UserLogin.GetSignaturex();
|
|
string html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html))
|
|
return;
|
|
if (html.Contains("\"data\""))
|
|
{
|
|
var userObj = Newtonsoft.Json.Linq.JObject.Parse(html);
|
|
foreach (Newtonsoft.Json.Linq.JObject obj in userObj["data"])
|
|
{
|
|
string oStr = JsonHelper.SerializeObject(obj);
|
|
DouShopSubAccountInfo user = new DouShopSubAccountInfo();
|
|
user.id = BaseRegex.GetIntJson(ref oStr, "id");
|
|
user.name = BaseRegex.GetStringJson(ref oStr, "name");
|
|
user.mobile = BaseRegex.GetStringJson(ref oStr, "mobile");
|
|
user.group_id = BaseRegex.GetStringJson(ref oStr, "group_id");
|
|
user.shop_count = BaseRegex.GetIntJson(ref oStr, "shop_count");
|
|
|
|
AllSubAccountList.Add(user);
|
|
}
|
|
|
|
if (shop != null)
|
|
{
|
|
ShopSubAccountList.AddRange(shop.ShopSubAccountList);
|
|
NotShopSubAccountList.AddRange(AllSubAccountList.Where(u => !ShopSubAccountList.Any(bu => bu.id == u.id)));
|
|
foreach (var item in ShopSubAccountList)
|
|
{
|
|
UcSubAccount s = new UcSubAccount(item, false);
|
|
s.AddSubAcountEvent += S_AddSubAcountEvent;
|
|
s.RemoveSubAcountEvent += S_RemoveSubAcountEvent;
|
|
flpShopSubAccount.Controls.Add(s);
|
|
}
|
|
foreach (var item in NotShopSubAccountList)
|
|
{
|
|
UcSubAccount s = new UcSubAccount(item);
|
|
s.AddSubAcountEvent += S_AddSubAcountEvent;
|
|
s.RemoveSubAcountEvent += S_RemoveSubAcountEvent;
|
|
flpNotSubAccount.Controls.Add(s);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void S_AddSubAcountEvent(object obj)
|
|
{
|
|
var s = obj as UcSubAccount;
|
|
if (s != null)
|
|
{
|
|
this.flpNotSubAccount.Controls.Remove(s);
|
|
this.flpShopSubAccount.Controls.Add(s);
|
|
}
|
|
}
|
|
|
|
private void S_RemoveSubAcountEvent(object obj)
|
|
{
|
|
var s = obj as UcSubAccount;
|
|
if (s != null)
|
|
{
|
|
this.flpShopSubAccount.Controls.Remove(s);
|
|
this.flpNotSubAccount.Controls.Add(s);
|
|
}
|
|
}
|
|
|
|
private void btnRemove_Click(object sender, EventArgs e)
|
|
{
|
|
var controls = this.flpShopSubAccount.Controls.Cast<Control>().ToList();
|
|
foreach (var c in controls)
|
|
{
|
|
(c as UcSubAccount).DeleteAccount();
|
|
}
|
|
}
|
|
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
var controls = this.flpNotSubAccount.Controls.Cast<Control>().ToList();
|
|
foreach (var c in controls)
|
|
{
|
|
(c as UcSubAccount).AddAccount();
|
|
}
|
|
}
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
{
|
|
List<DouShopSubAccountInfo> AddUsers = new List<DouShopSubAccountInfo>();
|
|
List<DouShopSubAccountInfo> DeleteUsers = new List<DouShopSubAccountInfo>();
|
|
foreach (Control c in this.flpNotSubAccount.Controls)
|
|
{
|
|
var co = c as UcSubAccount;
|
|
if (co == null)
|
|
continue;
|
|
|
|
if (ShopSubAccountList.Contains(co.subAccount))
|
|
{
|
|
DeleteUsers.Add(co.subAccount);
|
|
shop.ShopSubAccountList.Remove(co.subAccount);
|
|
string url = BaseClass.BuildObjString("shop&act=delete_shop_user_sub_group");
|
|
string data = UserLogin.GetSignaturex()
|
|
+ "&shop_id=" + shop.ShopAccountId
|
|
+ "&sub_user_id=" + co.subAccount.sub_user_id
|
|
+ "&status=" + co.subAccount.status
|
|
+ "&group_id=" + co.subAccount.group_id;
|
|
string html = GetHtml.PostUtf8(url, data);
|
|
}
|
|
}
|
|
foreach (Control c in this.flpShopSubAccount.Controls)
|
|
{
|
|
var co = c as UcSubAccount;
|
|
if (co == null)
|
|
continue;
|
|
|
|
if (NotShopSubAccountList.Contains(co.subAccount))
|
|
{
|
|
AddUsers.Add(co.subAccount);
|
|
shop.ShopSubAccountList.Add(co.subAccount);
|
|
string url = BaseClass.BuildObjString("shop&act=update_shop_user_sub_group");
|
|
string data = UserLogin.GetSignaturex()
|
|
+ "&shop_id=" + shop.ShopAccountId
|
|
+ "&sub_user_id=" + co.subAccount.sub_user_id
|
|
+ "&status=" + co.subAccount.status
|
|
+ "&group_id=" + co.subAccount.group_id;
|
|
string html = GetHtml.PostUtf8(url, data);
|
|
}
|
|
}
|
|
OnSaveComplete(shop);
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|