123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- using CCWin;
- using NamePipeClient;
- using NamePipeClient.Model;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using SufeiUtil;
- using System;
- using System.Collections.Generic;
- using System.Data.SQLite;
- using System.IO;
- using System.Net;
- using System.Net.Security;
- using System.Security.Cryptography.X509Certificates;
- using System.Text;
- using System.Windows.Forms;
- using Utils;
- namespace MOKA_Factory_Tools
- {
- public partial class login : Skin_Color
- {
- /// <summary>
- /// G客户NTF功能是否开启;
- /// </summary>
- public bool IsNTF { get; set; } = false;
- public int enable;
- string path = AppDomain.CurrentDomain.BaseDirectory;
- LoginOutput loginOutput1 = new LoginOutput()
- {
- factoryname = "",
- factorynum = ""
- };
- string ErrorDBPath = AppDomain.CurrentDomain.BaseDirectory + "\\Error.db";
- SQLiteConnection ErrorDB = null;
- private bool EnableSanhuaMES { get; set; } = false;
- public login()
- {
- InitializeComponent();
- AccountText.Focus();
- CommonMethod.CreateDirectory(path + "\\download");
- CommonMethod.CreateDirectory(path + "\\Keys");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\CIKEY");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\DeviceID");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\ESN");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\HDCPKEY");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\HDCPKEY22");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\MAC");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\Widevine");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\WiDi");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\Attestation");
- CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\MGK");
- if (!File.Exists(ErrorDBPath))
- {
- if (SQLiteHelper.NewDbFile(ErrorDBPath))
- {
- SQLiteHelper.NewTable(ErrorDBPath, "ErrorReport", "(ID INTEGER PRIMARY KEY AUTOINCREMENT,url varchar,content varvhar,gener_date DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')),report_date DATETIME)");
- SQLiteHelper.NewTable(ErrorDBPath, "CopyDelayReport", "(ID INTEGER PRIMARY KEY AUTOINCREMENT,bid varchar,url varchar,content varvhar,copy_date DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')),report_date DATETIME)");
- SQLiteHelper.NewTable(ErrorDBPath, "ProductionCount", "(bid varchar,count varchar)");
- }
- }
- if (ErrorDB == null)
- {
- ErrorDB = new SQLiteConnection("data source=" + ErrorDBPath);
- ErrorDB.Open();
- }
- getTestModeInfo();
- }
- private void getTestModeInfo()
- {
- // 读取win.ini或注册表;
- StringBuilder MyString = new StringBuilder(256);
- CommonMethod.GetProfileString("MOKAFactoryTools", "TestMode", "0", MyString, 256);
- if (MyString.ToString().Equals("1"))
- {
- TestMode.testMode = true;
- TestMode.SetTestMode(true);
- // 设置测试地址;
- V2Method.SetGetMessageUrl("http://test.scbc.qhmoka.com/scbc-server/clientType/getMessage.do");
- // 开启了测试模式;
- CommonMethod.GetProfileString("MOKAFactoryTools", "VirMAC", "B0-00-00-00-00-0B", MyString, 256);
- if (MyString.ToString().Equals("B0-00-00-00-00-0B"))
- {// 惠州工厂;
- AccountText.Text = "Huizhou";
- PwdText.Text = "admin";
- }
- else if (MyString.ToString().Equals("A0-00-00-00-00-0A"))
- {// 三华工厂;
- AccountText.Text = "SanHua";
- PwdText.Text = "admin";
- }
- else if (MyString.ToString().Equals("C0-00-00-00-00-0C"))
- {// 泰霖工厂;
- AccountText.Text = "Talent";
- PwdText.Text = "admin";
- }
- TestMode.MAC = MyString.ToString();
- JObject jObject;
- using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
- {
- using (JsonTextReader reader = new JsonTextReader(file))
- {
- jObject = (JObject)JToken.ReadFrom(reader);
- reader.Close();
- jObject["FactoryName"] = AccountText.Text;
- }
- }
- using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
- {
- writer.Write(jObject.ToString());
- }
- }
- else
- {
- TestMode.testMode = false;
- TestMode.SetTestMode();
- #if DEBUG
- TestMode.MAC = "C4-00-AD-17-61-3D&C4-00-AD-17-61-3C&";
- #else
- TestMode.MAC = CommonMethod.GetMacAddress();
- #endif
- }
- }
- private void OnBtnLogin(object sender, EventArgs e)
- {
- if (PwdText.Text == "zhangyi" && AccountText.Text == "zhangyi")
- enable = 1;
- else if (PwdText.Text == "offline" && AccountText.Text == "offline")
- enable = 3;
- else if (PwdText.Text.Trim().Length > 0 && AccountText.Text.Trim().Length > 0)
- {
- #region G客户NTF功能开启;
- if ( IsNTF )
- {
- if ( LineText.Text.Length == 0 )
- {
- MessageBox.Show("Line should not be empty!");
- return;
- }
- }
- #endregion
- if (CommonMethod.UserLogin(TestMode.loginUrl, AccountText.Text, PwdText.Text, TestMode.MAC, ErrorDB,out loginOutput1))
- {
- enable = 0;
- JObject jObject;
- using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
- {
- using (JsonTextReader reader = new JsonTextReader(file))
- {
- jObject = (JObject)JToken.ReadFrom(reader);
- reader.Close();
- jObject["FactoryName"] = loginOutput1.factoryname;
- jObject["FactoryNum"] = loginOutput1.factorynum;
- jObject["Line"] = LineText.Text;
- }
- }
- using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
- {
- writer.Write(jObject.ToString());
- }
- }
- else
- {
- MessageBox.Show(LResource.LoginFail + "\r\n" + loginOutput1.msg);
- return;
- }
- }
- else
- {
- enable = 2;
- }
- // 保存登录信息;
- CommonMethod.SaveLoginInfo(AccountText.Text, PwdText.Text);
- #region 三华MES登录数据
- if (EnableSanhuaMES)
- {
- if (CommonMethod.GetLoginAccout().Equals("Sanhua", StringComparison.OrdinalIgnoreCase))
- {
- SanhuaMES sanhuaMES = new SanhuaMES();
- if (sanhuaMES.ShowDialog() != DialogResult.OK)
- {
- return;
- }
- }
- }
- #endregion
- #region 进程通信
- // 启动服务;
- ProcUtils.StartService("FTYService");
- if (Utils.ProcUtils.IsServiceStart("FTYService"))
- {
- PipeClient client = new PipeClient("MOKA_FTYService", "127.0.0.1");
- if (client != null)
- {
- client.SendData(new ToolInfo()
- {
- appName = "SCBC Factory Tools",
- devicemodel = "SCBC Factory Tools",
- dnum = loginOutput1.factorynum,
- factoryname = loginOutput1.factoryname,
- procName = Application.ProductName,
- toolPath = AppDomain.CurrentDomain.BaseDirectory,
- toolVersion = Utils.FileUtils.GetAssemblyVersion(),
- type = "pc"
- }, 0);
- }
- }
- #endregion
- CommonMethod.FactoryName = loginOutput1.factoryname;
- UpgradeMsgList upgradeMsgList = new UpgradeMsgList();
- var FactoryNum = loginOutput1.factorynum;
- if(FactoryNum.Length>0)
- {
- try
- {
- if (CommonMethod.UpgradeCheck(TestMode.upgradeUrl, FactoryNum, ErrorDB, out upgradeMsgList))
- {
- if (CommonMethod.CompareVersion(upgradeMsgList.upgrade.version, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()))
- {
- Upgrade upgrade = new Upgrade(ErrorDB, upgradeMsgList.upgrade.fileurl, loginOutput1.factorynum);
- upgrade.Show();
- }
- else
- {
- ErrorDB.Close();
- ErrorDB.Dispose();
- Main form1 = new Main(enable);
- form1.Show();
- this.Hide();
- }
- }
- else
- {
- MessageBox.Show(LResource.UpgradeCheckFail);
- ErrorDB.Close();
- ErrorDB.Dispose();
- Main form1 = new Main(enable);
- form1.Show();
- this.Hide();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ServicePointManager.SecurityProtocol.ToString());
- MessageBox.Show(ex.Message);
- MessageBox.Show(LResource.UpgradeCheckFail);
- ErrorDB.Close();
- ErrorDB.Dispose();
- Main form1 = new Main(enable);
- form1.Show();
- this.Hide();
- }
- }
- else
- {
- ErrorDB.Close();
- ErrorDB.Dispose();
- MessageBox.Show(LResource.PleaseLogin);
- Main form1 = new Main(enable);
- form1.Show();
- this.Hide();
- }
- }
-
- public string format(uint data,uint length)
- {
- return String.Format("{0:D" + length.ToString() + "}", data);
- }
- private void login_Load(object sender, EventArgs e)
- {
- using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
- {
- using (JsonTextReader reader = new JsonTextReader(file))
- {
- JObject jObject = (JObject)JToken.ReadFrom(reader);
- reader.Close();
- AccountText.Text = jObject["FactoryName"] == null ? (!CommonMethod.AddJsonConfig("FactoryName", null) ? "" : "") : jObject["FactoryName"].Value<string>();
- loginOutput1.factoryname = jObject["FactoryName"] == null ? "" : jObject["FactoryName"].Value<string>();
- loginOutput1.factorynum=jObject["FactoryNum"] == null ? "" : jObject["FactoryNum"].Value<string>();
- HttpHelper.Tracert = jObject["Tracert"] == null ? false : jObject["Tracert"].Value<bool>();
- #region G客户NTF功能开启;
- if (jObject["NTF"] != null)
- {
- IsNTF = jObject["NTF"].Value<bool>();
- if (IsNTF)
- {
- skinLabel3.Visible = true;
- LineText.Visible = true;
- BtnLogin.Location = new System.Drawing.Point(70, 152);
- BtnLogin.Size = new System.Drawing.Size(90, 33);
- this.Size = new System.Drawing.Size(230, 200);
- }
- if (jObject["Line"] != null)
- {
- string Line = jObject["Line"].Value<string>();
- LineText.Text = Line;
- }
- }
- #endregion
- #region 加载三华登录数据库;
- if (jObject["SanhuaLoginInfo"] != null)
- {
- SanhuaMethod.sanhuaLoginInfo.url = jObject["SanhuaLoginInfo"]["url"].Value<string>();
- SanhuaMethod.sanhuaLoginInfo.staffCode = jObject["SanhuaLoginInfo"]["staffCode"].Value<string>();
- SanhuaMethod.sanhuaLoginInfo.password = jObject["SanhuaLoginInfo"]["password"].Value<string>();
- SanhuaMethod.sanhuaLoginInfo.resourceCode = jObject["SanhuaLoginInfo"]["resourceCode"].Value<string>();
- SanhuaMethod.sanhuaLoginInfo.jigEdtion = jObject["SanhuaLoginInfo"]["jigEdtion"].Value<string>();
- }
- if (jObject["EnableSanhuaMES"] != null )
- {
- EnableSanhuaMES = jObject["EnableSanhuaMES"].Value<bool>();
- }
- #endregion
- }
- }
- System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName("SCBC Factory Tools");//获取指定的进程名
- if (myProcesses.Length > 1)
- {
- MessageBox.Show(LResource.AlreadyRun);
- Application.Exit();
- }
- System.Diagnostics.Process[] myProcesses2 = System.Diagnostics.Process.GetProcessesByName("MOKA Factory Tools");//获取指定的进程名
- if (myProcesses2.Length > 1)
- {
- MessageBox.Show(LResource.AlreadyRun);
- Application.Exit();
- }
- }
- private void login_KeyDown(object sender, KeyEventArgs e)
- {
- // 判断是否回车登录;
- if (e.KeyCode == Keys.Enter)
- {
- OnBtnLogin(sender, e);
- }
- }
- private void PwdText_KeyDown(object sender, KeyEventArgs e)
- {
- // 判断是否回车登录;
- if (e.KeyCode == Keys.Enter)
- {
- OnBtnLogin(sender, e);
- }
- }
- private void LineText_KeyDown(object sender, KeyEventArgs e)
- {
- // 判断是否回车登录;
- if (e.KeyCode == Keys.Enter)
- {
- OnBtnLogin(sender, e);
- }
- }
- }
- }
|