145 lines
5.5 KiB
C#
145 lines
5.5 KiB
C#
using AllBase;
|
||
using AllBase.Model.Result;
|
||
using AllBase.Model.Result.WXResult;
|
||
using NaiBa.Util.Extension;
|
||
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 TemuKJD.BaseForms;
|
||
|
||
namespace TemuKJD.WXForms.ShopForms
|
||
{
|
||
public partial class WXShopDefaultAddressEditForm : BaseForms.BaseGeneralForm
|
||
{
|
||
List<ShopLoginInfo> lstShop = new List<ShopLoginInfo>();
|
||
ShopLoginInfo shop = null;
|
||
WXShopDefaultAddressInfo address = null;
|
||
|
||
public WXShopDefaultAddressEditForm(List<ShopLoginInfo> shopLst)
|
||
{
|
||
InitializeComponent();
|
||
|
||
if (shopLst != null)
|
||
lstShop.AddRange(shopLst);
|
||
}
|
||
|
||
private void WXShopDefaultAddressEditForm_Load(object sender, EventArgs e)
|
||
{
|
||
lblStatus.Text = "";
|
||
if (lstShop.Count > 0)
|
||
{
|
||
ShowShopDefaultAddress();
|
||
}
|
||
}
|
||
|
||
void ShowShopDefaultAddress()
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
shop = this.lstShop.FirstOrDefault();
|
||
if (shop == null)
|
||
return;
|
||
address = WXShopDefaultAddressListForm.GetShopDefaultAddressLst(new List<ShopLoginInfo> { shop }, false).FirstOrDefault();
|
||
if (address == null)
|
||
address = new WXShopDefaultAddressInfo();
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.txtShopId.Text = shop.ShopId;
|
||
this.txtShopName.Text = shop.ShopAccount;
|
||
if (lstShop.Count > 1)
|
||
{
|
||
txtShopId.Text += " 等 " + lstShop.Count + " 家店铺";
|
||
txtShopName.Text += " 等 " + lstShop.Count + " 家店铺";
|
||
}
|
||
|
||
this.txtProvinceName.Text = address.province_name;
|
||
this.txtCityName.Text = address.city_name;
|
||
this.txtCountyName.Text = address.county_name;
|
||
this.txtTelNumber.Text = address.tel_number;
|
||
this.txtDetailInfo.Text = address.detail_info;
|
||
this.txtUserName.Text = address.user_name;
|
||
}));
|
||
});
|
||
}
|
||
|
||
private void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (txtCityName.Text.Trim().IsNullOrEmpty() || txtCountyName.Text.Trim().IsNullOrEmpty() || txtDetailInfo.Text.Trim().IsNullOrEmpty() ||
|
||
txtProvinceName.Text.Trim().IsNullOrEmpty() || txtShopId.Text.Trim().IsNullOrEmpty() || txtShopName.Text.Trim().IsNullOrEmpty() ||
|
||
txtTelNumber.Text.Trim().IsNullOrEmpty() || txtUserName.Text.Trim().IsNullOrEmpty())
|
||
{
|
||
BaseMsgForm.ShowError("请填写所有字段");
|
||
return;
|
||
}
|
||
|
||
if (lstShop == null || lstShop.Count==0)
|
||
{
|
||
BaseMsgForm.ShowError("店铺信息不能为空");
|
||
return;
|
||
}
|
||
|
||
Task.Run(() =>
|
||
{
|
||
int index = 0;
|
||
int successCount = 0;
|
||
int failCount = 0;
|
||
string updateMsg = "";
|
||
foreach (var shop in lstShop)
|
||
{
|
||
index++;
|
||
Invoke(new Action(() =>
|
||
{
|
||
lblStatus.Text = "正在更新店铺默认地址 " + index + "/" + lstShop.Count;
|
||
}));
|
||
|
||
var url = BaseClass.BuildObjString("shop/wx_add_mdy_shop_default_address");
|
||
var data = Work.UserLogin.GetSignaturex();
|
||
data += "&shop_id=" + shop.ShopId;
|
||
data += "&province_name=" + GetHtml.UrlEncodeUtf8(txtProvinceName.Text.Trim());
|
||
data += "&city_name=" + GetHtml.UrlEncodeUtf8(txtCityName.Text.Trim());
|
||
data += "&county_name=" + GetHtml.UrlEncodeUtf8(txtCountyName.Text.Trim());
|
||
data += "&detail_info=" + GetHtml.UrlEncodeUtf8(txtDetailInfo.Text.Trim());
|
||
data += "&tel_number=" + GetHtml.UrlEncodeUtf8(txtTelNumber.Text.Trim());
|
||
data += "&receiver=" + GetHtml.UrlEncodeUtf8(txtUserName.Text.Trim()); // 收件人
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (!html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (!html.Contains("\"code\":200"))
|
||
{
|
||
var errMsg = BaseRegex.GetStringJson(ref html, "msg");
|
||
if (errMsg.IsNullOrEmpty())
|
||
errMsg = html;
|
||
|
||
updateMsg += "店铺 " + shop.ShopAccount + " 操作失败:" + errMsg + ",";
|
||
failCount++;
|
||
}
|
||
else
|
||
{
|
||
successCount++;
|
||
}
|
||
}
|
||
|
||
this.OnSaveComplete(updateMsg, true, this);
|
||
if (!string.IsNullOrEmpty(updateMsg))
|
||
BaseMsgForm.ShowError(updateMsg);
|
||
else
|
||
{
|
||
Invoke(new Action(() => { this.Close(); }));
|
||
}
|
||
});
|
||
}
|
||
|
||
private void pnlCancel_Click(object sender, EventArgs e)
|
||
{
|
||
this.Close();
|
||
}
|
||
}
|
||
}
|