SanhuaMES.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using CCWin;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace MOKA_Factory_Tools
  15. {
  16. public partial class SanhuaMES : Skin_Color
  17. {
  18. public SanhuaMES()
  19. {
  20. InitializeComponent();
  21. }
  22. private void SanhuaMES_Load(object sender, EventArgs e)
  23. {
  24. Text_MES_URL.Text = SanhuaMethod.sanhuaLoginInfo.url;
  25. Text_StaffCode.Text = SanhuaMethod.sanhuaLoginInfo.staffCode;
  26. Text_ResuorceCode.Text = SanhuaMethod.sanhuaLoginInfo.resourceCode;
  27. Text_MES_Password.Text = SanhuaMethod.sanhuaLoginInfo.password;
  28. Text_JigEdtion.Text = SanhuaMethod.sanhuaLoginInfo.jigEdtion;
  29. }
  30. private void Btn_MES_Login_Click(object sender, EventArgs e)
  31. {
  32. SanhuaMethod.sanhuaLoginInfo.url = Text_MES_URL.Text;
  33. SanhuaMethod.sanhuaLoginInfo.staffCode = Text_StaffCode.Text;
  34. SanhuaMethod.sanhuaLoginInfo.resourceCode = Text_ResuorceCode.Text;
  35. SanhuaMethod.sanhuaLoginInfo.password = Text_MES_Password.Text;
  36. SanhuaMethod.sanhuaLoginInfo.jigEdtion = Text_JigEdtion.Text;
  37. if ( !SanhuaMethod.sanhuaLoginInfo.url.EndsWith("/") )
  38. {
  39. SanhuaMethod.sanhuaLoginInfo.url += "/";
  40. }
  41. SaveLoginInfo();
  42. string message = string.Empty;
  43. if ( SanhuaMethod.CheckLogin(out message) )
  44. {
  45. DialogResult = DialogResult.OK;
  46. }
  47. else
  48. {
  49. MessageBox.Show(string.Format("登录失败:{0}", message));
  50. DialogResult = DialogResult.Cancel;
  51. }
  52. }
  53. private void SaveLoginInfo()
  54. {
  55. JObject jObject;
  56. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  57. {
  58. using (JsonTextReader reader = new JsonTextReader(file))
  59. {
  60. jObject = (JObject)JToken.ReadFrom(reader);
  61. reader.Close();
  62. if (jObject["SanhuaLoginInfo"] == null)
  63. {
  64. JObject item = new JObject();
  65. item.Add("url", SanhuaMethod.sanhuaLoginInfo.url);
  66. item.Add("staffCode", SanhuaMethod.sanhuaLoginInfo.staffCode);
  67. item.Add("resourceCode", SanhuaMethod.sanhuaLoginInfo.resourceCode);
  68. item.Add("password", SanhuaMethod.sanhuaLoginInfo.password);
  69. item.Add("jigEdtion", SanhuaMethod.sanhuaLoginInfo.jigEdtion);
  70. jObject.Add("SanhuaLoginInfo", item);
  71. }
  72. else
  73. {
  74. jObject["SanhuaLoginInfo"]["url"] = SanhuaMethod.sanhuaLoginInfo.url;
  75. jObject["SanhuaLoginInfo"]["staffCode"] = SanhuaMethod.sanhuaLoginInfo.staffCode;
  76. jObject["SanhuaLoginInfo"]["resourceCode"] = SanhuaMethod.sanhuaLoginInfo.resourceCode;
  77. jObject["SanhuaLoginInfo"]["password"] = SanhuaMethod.sanhuaLoginInfo.password;
  78. jObject["SanhuaLoginInfo"]["jigEdtion"] = SanhuaMethod.sanhuaLoginInfo.jigEdtion;
  79. }
  80. }
  81. }
  82. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  83. {
  84. writer.Write(jObject.ToString());
  85. }
  86. }
  87. }
  88. }