Files
kami_itunes_june/AppleBatch_June/addMaterial.cs
danial 06b0fcce08 chore(build): 更新项目配置和依赖以支持.NET 8
- 在.settings.local.json中添加dotnet clean命令权限
- 更新项目文件以启用不安全的二进制序列化和禁用平台兼容性警告
- 配置调试和发布模式的编译常量及优化选项
- 在解决方案文件中升级Visual Studio版本并添加多平台配置
- 移除FormLogin构造函数中的MessageBox调试代码
- 为过时的WebRequest、WebClient和ServicePointManager API添加编译警告抑制
- 简化异常处理逻辑并在Program.cs中改进启动流程
- 移除多个未使用的局部变量声明
- 添加launchSettings.json以支持开发环境配置
- 在表单构造函数中初始化components容器
- 优化网络请求超时设置并改善错误处理机制
2025-11-10 19:34:27 +08:00

551 lines
19 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using System.Windows.Forms;
using AppleBatch_June.Domain;
using AppleBatch_June.Model;
using AppleBatch_June.Properties;
using DotNet.Utilities;
namespace AppleBatch_June
{
public class addMaterial : Form
{
private CountriesReachableAt reachableAt;
private IContainer components;
private ComboBox txtGuojia;
private Label label1;
private Button button1;
private GroupBox groupBox1;
private TextBox txtSuburb;
private Label label11;
private Label label10;
private TextBox txtDianhua;
private Label label8;
private TextBox txtQuhao;
private Label label9;
private TextBox txtYoubian;
private Label label7;
private TextBox txtChegnshi;
private Label label6;
private TextBox txtLouhao;
private Label label5;
private TextBox txtJieDao;
private Label label4;
private TextBox txtMing;
private Label label3;
private TextBox txtXing;
private Label label2;
private TextBox txtCounty;
private Label label12;
private ComboBox comSheng;
private TextBox txtNote;
private Label label13;
private TextBox txttaxId;
private Label label14;
public addMaterial()
{
components = new Container();
InitializeComponent();
}
private void addMaterial_Load(object sender, EventArgs e)
{
txtGuojia.Sorted = true;
HttpItem item = new HttpItem
{
URL = ApiNetReq.host + "/js/supportedCountries.json",
Method = "GET",
Timeout = 10000,
ResultType = ResultType.String
};
using HttpHelper httpHelper = new HttpHelper();
HttpResult html = httpHelper.GetHtml(item);
CountriesReachableAt.Smssupportedcountriesreachableat[] smsSupportedCountriesReachableAt;
if (html.StatusCode == HttpStatusCode.OK)
{
reachableAt = JsonConvert.DeserializeObject<CountriesReachableAt>(html.Html);
smsSupportedCountriesReachableAt = reachableAt.smsSupportedCountriesReachableAt;
foreach (CountriesReachableAt.Smssupportedcountriesreachableat smssupportedcountriesreachableat in smsSupportedCountriesReachableAt)
{
txtGuojia.Items.Add(smssupportedcountriesreachableat.name + "-" + smssupportedcountriesreachableat.code);
}
return;
}
string @string = Encoding.UTF8.GetString(Resources.localizedResources);
reachableAt = JsonConvert.DeserializeObject<CountriesReachableAt>(@string);
smsSupportedCountriesReachableAt = reachableAt.smsSupportedCountriesReachableAt;
foreach (CountriesReachableAt.Smssupportedcountriesreachableat smssupportedcountriesreachableat2 in smsSupportedCountriesReachableAt)
{
txtGuojia.Items.Add(smssupportedcountriesreachableat2.name + "-" + smssupportedcountriesreachableat2.code);
}
}
public HttpResult getCitityInfo(string citity)
{
HttpItem httpItem = new HttpItem
{
URL = "https://appleid.apple.com/resources/addressFormat/" + citity,
Method = "GET",
Timeout = 100000,
ReadWriteTimeout = 30000,
IsToLower = false,
Cookie = " dslang=CN-ZH; geo=CN;",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36",
Accept = "application/json",
ContentType = "application/json",
Referer = "https://appleid.apple.com/account/manage",
WebProxy = WebRequest.DefaultWebProxy,
ResultType = ResultType.String
};
httpItem.Header.Add("X-Apple-Api-Key", "cbf64fd6843ee630b463f358ea0b707b");
httpItem.Header.Add("X-Requested-With", "XMLHttpRequest");
httpItem.Header.Add("Accept-Encoding", "gzip, deflate");
return new HttpHelper().GetHtml(httpItem);
}
private void txtGuojia_SelectedIndexChanged(object sender, EventArgs e)
{
string text = txtGuojia.Text;
if (string.IsNullOrEmpty(text))
{
return;
}
string citity = text.Split('-')[1];
HttpResult citityInfo = getCitityInfo(citity);
if (citityInfo.StatusCode == HttpStatusCode.OK)
{
groupBox1.Enabled = true;
TextBox textBox = txttaxId;
TextBox textBox2 = txtQuhao;
TextBox textBox3 = txtCounty;
TextBox textBox4 = txtSuburb;
TextBox textBox5 = txtChegnshi;
TextBox textBox6 = txtYoubian;
TextBox textBox7 = txtJieDao;
TextBox textBox8 = txtLouhao;
comSheng.Enabled = true;
textBox8.Enabled = true;
textBox7.Enabled = true;
textBox6.Enabled = true;
textBox5.Enabled = true;
textBox4.Enabled = true;
textBox3.Enabled = true;
textBox2.Enabled = true;
textBox.Enabled = true;
dynamic val = Tools.Todejosn<object>(citityInfo.Html);
Dictionary<string, object> dictionary = val["fields"];
if (!dictionary.ContainsKey("phoneAreaCode"))
{
txtQuhao.Enabled = false;
}
else
{
txtQuhao.Enabled = true;
}
if (!dictionary.ContainsKey("county"))
{
txtCounty.Enabled = false;
}
if (!dictionary.ContainsKey("suburb"))
{
txtSuburb.Enabled = false;
}
if (!dictionary.ContainsKey("city"))
{
txtChegnshi.Enabled = false;
}
if (!dictionary.ContainsKey("postalCode"))
{
txtYoubian.Enabled = false;
}
if (!dictionary.ContainsKey("line1"))
{
txtJieDao.Enabled = false;
}
if (!dictionary.ContainsKey("line2"))
{
txtLouhao.Enabled = false;
}
if (!dictionary.ContainsKey("taxId"))
{
txttaxId.Enabled = false;
}
if (!dictionary.ContainsKey("stateProvince"))
{
comSheng.Enabled = false;
return;
}
comSheng.Items.Clear();
foreach (dynamic item2 in ((dynamic)dictionary["stateProvince"])["values"])
{
string item = item2["title"] + "【" + item2["name"] + "】";
comSheng.Items.Add(item);
}
if (comSheng.Items.Count > 0)
{
comSheng.SelectedIndex = 0;
}
}
else
{
MessageBox.Show("网络错误");
}
}
private void txtQuhao_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string text = txtGuojia.Text;
if (string.IsNullOrEmpty(text))
{
return;
}
string[] tmp = text.Split('-');
if (tmp.Length > 1)
{
CountriesReachableAt.Smssupportedcountriesreachableat smssupportedcountriesreachableat = reachableAt.smsSupportedCountriesReachableAt.Where((CountriesReachableAt.Smssupportedcountriesreachableat c) => c.code == tmp[1]).FirstOrDefault();
if (smssupportedcountriesreachableat != null)
{
string stateProvinceName = "";
if (comSheng.Enabled)
{
stateProvinceName = new Regex("【([\\s\\S]*?)】").Match(comSheng.Text).Groups[1].Value;
}
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.billingAddress = new PaymentInfo.Billingaddress
{
city = txtChegnshi.Text,
countryCode = smssupportedcountriesreachableat.code,
county = txtCounty.Text,
suburb = txtSuburb.Text,
postalCode = txtYoubian.Text,
stateProvinceName = stateProvinceName,
line1 = txtJieDao.Text,
line2 = txtLouhao.Text,
line3 = ""
};
paymentInfo.ownerName = new PaymentInfo.Ownername
{
firstName = txtMing.Text,
lastName = txtXing.Text
};
paymentInfo.phoneNumber = new PaymentInfo.Phonenumber
{
countryCode = smssupportedcountriesreachableat.dialCode,
areaCode = txtQuhao.Text,
number = txtDianhua.Text
};
if (!string.IsNullOrEmpty(txttaxId.Text))
{
paymentInfo.webAppend = "taxId=" + txttaxId.Text.Trim();
paymentInfo.itAppend = "taxId=" + txttaxId.Text.Trim();
}
new UserNationalData().saveMation(new NationalList
{
Id = Tools.GenerateTimeStamp().ToString(),
name = smssupportedcountriesreachableat.name + ((!string.IsNullOrEmpty(txtNote.Text)) ? ("(" + txtNote.Text.Trim() + ")") : "") + " - " + txtXing.Text + txtMing.Text,
payment = paymentInfo
});
base.DialogResult = DialogResult.OK;
}
}
else
{
MessageBox.Show("请先选择国家");
}
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.txtGuojia = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.comSheng = new System.Windows.Forms.ComboBox();
this.txtCounty = new System.Windows.Forms.TextBox();
this.label12 = new System.Windows.Forms.Label();
this.txtSuburb = new System.Windows.Forms.TextBox();
this.label11 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.txtDianhua = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.txtQuhao = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.txtYoubian = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.txtChegnshi = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtLouhao = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.txtJieDao = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtMing = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtXing = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtNote = new System.Windows.Forms.TextBox();
this.label13 = new System.Windows.Forms.Label();
this.txttaxId = new System.Windows.Forms.TextBox();
this.label14 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
base.SuspendLayout();
this.txtGuojia.Font = new System.Drawing.Font("楷体", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
this.txtGuojia.FormattingEnabled = true;
this.txtGuojia.Location = new System.Drawing.Point(123, 23);
this.txtGuojia.Name = "txtGuojia";
this.txtGuojia.Size = new System.Drawing.Size(210, 22);
this.txtGuojia.TabIndex = 23;
this.txtGuojia.SelectedIndexChanged += new System.EventHandler(txtGuojia_SelectedIndexChanged);
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(14, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(105, 14);
this.label1.TabIndex = 22;
this.label1.Text = "选择国家或地区";
this.button1.Location = new System.Drawing.Point(123, 528);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(173, 51);
this.button1.TabIndex = 21;
this.button1.Text = "保存国家";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(button1_Click);
this.groupBox1.Controls.Add(this.txttaxId);
this.groupBox1.Controls.Add(this.label14);
this.groupBox1.Controls.Add(this.comSheng);
this.groupBox1.Controls.Add(this.txtCounty);
this.groupBox1.Controls.Add(this.label12);
this.groupBox1.Controls.Add(this.txtSuburb);
this.groupBox1.Controls.Add(this.label11);
this.groupBox1.Controls.Add(this.label10);
this.groupBox1.Controls.Add(this.txtDianhua);
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.txtQuhao);
this.groupBox1.Controls.Add(this.label9);
this.groupBox1.Controls.Add(this.txtYoubian);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.txtChegnshi);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.txtLouhao);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.txtJieDao);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.txtMing);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.txtXing);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Enabled = false;
this.groupBox1.Location = new System.Drawing.Point(32, 62);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(418, 436);
this.groupBox1.TabIndex = 24;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "帐单寄送地址";
this.comSheng.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comSheng.FormattingEnabled = true;
this.comSheng.Location = new System.Drawing.Point(77, 320);
this.comSheng.Name = "comSheng";
this.comSheng.Size = new System.Drawing.Size(329, 22);
this.comSheng.TabIndex = 66;
this.txtCounty.Location = new System.Drawing.Point(77, 192);
this.txtCounty.Name = "txtCounty";
this.txtCounty.Size = new System.Drawing.Size(329, 23);
this.txtCounty.TabIndex = 65;
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(42, 199);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(21, 14);
this.label12.TabIndex = 64;
this.label12.Text = "县";
this.txtSuburb.Location = new System.Drawing.Point(77, 153);
this.txtSuburb.Name = "txtSuburb";
this.txtSuburb.Size = new System.Drawing.Size(329, 23);
this.txtSuburb.TabIndex = 63;
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(42, 160);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(21, 14);
this.label11.TabIndex = 62;
this.label11.Text = "区";
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(6, 323);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(70, 14);
this.label10.TabIndex = 60;
this.label10.Text = "选择省/市";
this.txtDianhua.Location = new System.Drawing.Point(239, 367);
this.txtDianhua.Name = "txtDianhua";
this.txtDianhua.Size = new System.Drawing.Size(167, 23);
this.txtDianhua.TabIndex = 59;
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(183, 372);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(35, 14);
this.label8.TabIndex = 58;
this.label8.Text = "电话";
this.txtQuhao.Location = new System.Drawing.Point(79, 366);
this.txtQuhao.Name = "txtQuhao";
this.txtQuhao.Size = new System.Drawing.Size(89, 23);
this.txtQuhao.TabIndex = 57;
this.txtQuhao.TextChanged += new System.EventHandler(txtQuhao_TextChanged);
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(29, 372);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(35, 14);
this.label9.TabIndex = 56;
this.label9.Text = "区号";
this.txtYoubian.Location = new System.Drawing.Point(79, 276);
this.txtYoubian.Name = "txtYoubian";
this.txtYoubian.Size = new System.Drawing.Size(329, 23);
this.txtYoubian.TabIndex = 55;
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(29, 282);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(35, 14);
this.label7.TabIndex = 54;
this.label7.Text = "邮编";
this.txtChegnshi.Location = new System.Drawing.Point(79, 232);
this.txtChegnshi.Name = "txtChegnshi";
this.txtChegnshi.Size = new System.Drawing.Size(329, 23);
this.txtChegnshi.TabIndex = 53;
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(29, 238);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(35, 14);
this.label6.TabIndex = 52;
this.label6.Text = "城市";
this.txtLouhao.Location = new System.Drawing.Point(79, 112);
this.txtLouhao.Name = "txtLouhao";
this.txtLouhao.Size = new System.Drawing.Size(329, 23);
this.txtLouhao.TabIndex = 51;
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(5, 117);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(70, 14);
this.label5.TabIndex = 50;
this.label5.Text = "楼号,单元";
this.txtJieDao.Location = new System.Drawing.Point(79, 70);
this.txtJieDao.Name = "txtJieDao";
this.txtJieDao.Size = new System.Drawing.Size(329, 23);
this.txtJieDao.TabIndex = 49;
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 73);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(63, 14);
this.label4.TabIndex = 48;
this.label4.Text = "街道地址";
this.txtMing.Location = new System.Drawing.Point(233, 28);
this.txtMing.Name = "txtMing";
this.txtMing.Size = new System.Drawing.Size(175, 23);
this.txtMing.TabIndex = 47;
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(184, 31);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 14);
this.label3.TabIndex = 46;
this.label3.Text = "名字";
this.txtXing.Location = new System.Drawing.Point(79, 25);
this.txtXing.Name = "txtXing";
this.txtXing.Size = new System.Drawing.Size(89, 23);
this.txtXing.TabIndex = 45;
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(29, 29);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 14);
this.label2.TabIndex = 44;
this.label2.Text = "姓氏";
this.txtNote.Location = new System.Drawing.Point(380, 22);
this.txtNote.Name = "txtNote";
this.txtNote.Size = new System.Drawing.Size(96, 23);
this.txtNote.TabIndex = 25;
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(339, 27);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(35, 14);
this.label13.TabIndex = 26;
this.label13.Text = "备注";
this.txttaxId.Location = new System.Drawing.Point(77, 403);
this.txttaxId.Name = "txttaxId";
this.txttaxId.Size = new System.Drawing.Size(329, 23);
this.txttaxId.TabIndex = 68;
this.label14.AutoSize = true;
this.label14.Location = new System.Drawing.Point(8, 406);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(63, 14);
this.label14.TabIndex = 67;
this.label14.Text = "附加税号";
base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 14f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new System.Drawing.Size(488, 600);
base.Controls.Add(this.label13);
base.Controls.Add(this.txtNote);
base.Controls.Add(this.groupBox1);
base.Controls.Add(this.txtGuojia);
base.Controls.Add(this.label1);
base.Controls.Add(this.button1);
this.Font = new System.Drawing.Font("隶书", 10.5f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
base.MaximizeBox = false;
base.MinimizeBox = false;
base.Name = "addMaterial";
base.ShowIcon = false;
base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "新增国家";
base.Load += new System.EventHandler(addMaterial_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
base.ResumeLayout(false);
base.PerformLayout();
}
}
}