public static void Main(string[] args) { //args = new string[] { "CBADONGTIEN1" }; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(defaultValue: false); BonusSkins.Register(); OfficeSkins.Register(); string defaultStyle2 = "Money Twins"; DefaultLookAndFeel defaultLookAndFeelMain2 = new DefaultLookAndFeel(); if (defaultStyle2 != string.Empty) { defaultLookAndFeelMain2.LookAndFeel.SetSkinStyle(defaultStyle2); } string H_KEY = "HKEY_CURRENT_USER\\Software\\SGD\\"; RegistryKey HKey = Registry.CurrentUser.OpenSubKey("Software\\SGD\\"); if (HKey == null) { Registry.CurrentUser.CreateSubKey("Software\\SGD\\"); HKey = Registry.CurrentUser.OpenSubKey("Software\\SGD\\"); } string server = ConfigurationSettings.AppSettings["WebServer"]; Config.NewKeyValue("WebServer", server); string productName3 = "CBABPM"; string[] softList = HKey.GetSubKeyNames(); string P_KEY2 = ""; if (args.Length != 0) { productName3 = args[0]; softList = new[] { args[0] }; } if (softList.Length > 1) { fSoftList fsl = new fSoftList(); fsl.ShowDialog(); productName3 = fsl.Productname; P_KEY2 = H_KEY + productName3 + "\\"; if (productName3 == string.Empty) { return; } } else if (softList.Length == 0) { //productName3 = "CBASGD133"; string subkey = "Software\\SGD\\" + productName3; P_KEY2 = H_KEY + productName3 + "\\"; RegistryKey pKey = Registry.CurrentUser.OpenSubKey(subkey); if (pKey == null) { Registry.CurrentUser.CreateSubKey(subkey); Registry.SetValue(P_KEY2, "CompanyName", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "Created", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "isDemo", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "Language", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "Package", "7", RegistryValueKind.String); Registry.SetValue(P_KEY2, "isOnline", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "Password", "20-2C-B9-62-AC-59-07-5B-96-4B-07-15-2D-23-4B-70", RegistryValueKind.ExpandString); Registry.SetValue(P_KEY2, "RegisterNumber", "", RegistryValueKind.String); Registry.SetValue(P_KEY2, "SavePassword", "True", RegistryValueKind.String); Registry.SetValue(P_KEY2, "StructDb", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "RemoteServer", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "Style", "Money Twins", RegistryValueKind.String); Registry.SetValue(P_KEY2, "SupportOnline", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "UserName", "Admin", RegistryValueKind.String); Registry.SetValue(P_KEY2, "isRemote", "False", RegistryValueKind.String); Registry.SetValue(P_KEY2, "SoftType", "0", RegistryValueKind.DWord); } } else { productName3 = softList[0]; P_KEY2 = H_KEY + productName3 + "\\"; } Config.NewKeyValue("ProductName", productName3); Config.NewKeyValue("H_KEY", P_KEY2); defaultStyle2 = Registry.GetValue(P_KEY2, "Style", string.Empty).ToString(); defaultLookAndFeelMain2 = new DefaultLookAndFeel(); if (defaultStyle2 != string.Empty) { defaultLookAndFeelMain2.LookAndFeel.SetSkinStyle(defaultStyle2); } string created = Registry.GetValue(P_KEY2, "Created", 0).ToString(); if (created == "0") { CreateData frmCreateData = new CreateData(productName3); frmCreateData.ShowDialog(); if (frmCreateData.DialogResult == DialogResult.Cancel) { return; } Registry.SetValue(P_KEY2, "Created", 1); } Config.NewKeyValue("H_KEY", P_KEY2); int SoftType = (int)Registry.GetValue(P_KEY2, "SoftType", 1); int isOnline = 0; try { isOnline = (int)Registry.GetValue(P_KEY2, "isOnline", 0); } catch { } string extend = isOnline == 0 ? "" : "1"; string Company = Registry.GetValue(P_KEY2, "CompanyName", "").ToString(); CPUid Cpu = (SoftType != 0) ? new CPUid(Company + productName3 + "SGDBPMOnline" + extend) : new CPUid(Company + productName3 + "SGDEMTOnline" + extend); string RegisterNumber = Registry.GetValue(P_KEY2, "RegisterNumber", "").ToString(); if (RegisterNumber != Cpu.KeyString) { Config.NewKeyValue("isDemo", 1); if (MessageBox.Show("Bạn đang dùng phiên bản demo, bạn có muốn đăng ký lại không?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes) { RegisterF rf = new RegisterF(); rf.producName = productName3; rf.ShowDialog(); Config.NewKeyValue("isDemo", 0); if (rf.DialogResult == DialogResult.Cancel) { return; } RegisterNumber = rf.textEditValue.Text; } } else { Config.NewKeyValue("isDemo", 0); Config.NewKeyValue("CompanyName", Company); Config.NewKeyValue("SoftType", SoftType); Config.NewKeyValue("isOnline", isOnline); } SetEnvironment(); //Check data online phải có register trên server Login frmLogin = new Login(); frmLogin.ShowDialog(); if (frmLogin.DialogResult != DialogResult.Cancel) { if (isOnline == 1)//Kiểm tra ngày hết hạn { try { CDTControl.Log log = new CDTControl.Log(); string uKey = log.GetExDate(RegisterNumber); UserKey key = JsonConvert.DeserializeObject <UserKey>(uKey); if (key == null) { if (File.Exists(productName3 + ".txt")) { MessageBox.Show("Máy bạn đã hết hạn sử dụng gói phần mềm này! \n Liên hệ : 0935.45.75.15 Vỹ Công Trần để được hướng dẫn"); return; } else { MessageBox.Show("Bạn cần kết nối internet để kiểm tra cập nhật mới nhất!"); } } else if (DateTime.Now > key.Exdate) { MessageBox.Show("Máy bạn đã hết hạn sử dụng gói phần mềm này! \n Liên hệ : 00935.45.75.15 Vỹ Công Trần để được hướng dẫn"); LogFile.CreateFile(productName3 + ".txt"); return; } else { LogFile.DeleteFile(productName3 + ".txt"); } } catch { } } Application.Run(new Main(frmLogin.drUser, frmLogin.drPackage)); } }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(defaultValue: false); BonusSkins.Register(); OfficeSkins.Register(); string defaultStyle2 = "Money Twins"; DefaultLookAndFeel defaultLookAndFeelMain2 = new DefaultLookAndFeel(); if (defaultStyle2 != string.Empty) { defaultLookAndFeelMain2.LookAndFeel.SetSkinStyle(defaultStyle2); } string server = ConfigurationSettings.AppSettings["WebServer"]; Config.NewKeyValue("WebServer", server); string productName3 = "CBASGD133"; if (args.Length != 0) { productName3 = args[0]; } string H_KEY = "HKEY_CURRENT_USER\\Software\\SGD\\"; RegistryKey HKey = Registry.CurrentUser.OpenSubKey("Software\\SGD\\"); if (HKey == null) { Registry.CurrentUser.CreateSubKey("Software\\SGD\\"); HKey = Registry.CurrentUser.OpenSubKey("Software\\SGD\\"); } string[] softList = HKey.GetSubKeyNames(); string P_KEY2 = ""; if (softList.Length > 1) { fSoftList fsl = new fSoftList(); fsl.ShowDialog(); productName3 = fsl.Productname; P_KEY2 = H_KEY + productName3 + "\\"; if (productName3 == string.Empty) { return; } } else if (softList.Length == 0) { productName3 = "CBASGD133"; string subkey = "Software\\SGD\\" + productName3; P_KEY2 = H_KEY + productName3 + "\\"; RegistryKey pKey = Registry.CurrentUser.OpenSubKey(subkey); if (pKey == null) { Registry.CurrentUser.CreateSubKey(subkey); Registry.SetValue(P_KEY2, "CompanyName", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "Created", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "isDemo", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "Language", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "Package", "7", RegistryValueKind.String); Registry.SetValue(P_KEY2, "isOnline", "0", RegistryValueKind.DWord); Registry.SetValue(P_KEY2, "Password", "20-2C-B9-62-AC-59-07-5B-96-4B-07-15-2D-23-4B-70", RegistryValueKind.ExpandString); Registry.SetValue(P_KEY2, "RegisterNumber", "", RegistryValueKind.String); Registry.SetValue(P_KEY2, "SavePassword", "True", RegistryValueKind.String); Registry.SetValue(P_KEY2, "StructDb", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "RemoteServer", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "Style", "Money Twins", RegistryValueKind.String); Registry.SetValue(P_KEY2, "SupportOnline", "SGD", RegistryValueKind.String); Registry.SetValue(P_KEY2, "UserName", "Admin", RegistryValueKind.String); Registry.SetValue(P_KEY2, "isRemote", "False", RegistryValueKind.String); Registry.SetValue(P_KEY2, "SoftType", "0", RegistryValueKind.DWord); } } else { productName3 = softList[0]; P_KEY2 = H_KEY + productName3 + "\\"; } Config.NewKeyValue("ProductName", productName3); Config.NewKeyValue("H_KEY", P_KEY2); defaultStyle2 = Registry.GetValue(P_KEY2, "Style", string.Empty).ToString(); defaultLookAndFeelMain2 = new DefaultLookAndFeel(); if (defaultStyle2 != string.Empty) { defaultLookAndFeelMain2.LookAndFeel.SetSkinStyle(defaultStyle2); } string created = Registry.GetValue(P_KEY2, "Created", 0).ToString(); int isOnline = 0; try { isOnline = (int)Registry.GetValue(P_KEY2, "isOnline", 0); } catch { } Config.NewKeyValue("H_KEY", P_KEY2); int SoftType = (int)Registry.GetValue(P_KEY2, "SoftType", 1); string extend = "1"; string Company = Registry.GetValue(P_KEY2, "CompanyName", "").ToString(); CPUid Cpu = new CPUid(Company + productName3 + "SGDBPMOnline" + extend); string RegisterNumber = Registry.GetValue(P_KEY2, "RegisterNumber", "").ToString(); if (RegisterNumber != Cpu.KeyString) { Config.NewKeyValue("isDemo", 1); if (MessageBox.Show("Bạn đang dùng phiên bản demo, bạn có muốn đăng ký lại không?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes) { RegisterF rf = new RegisterF(); rf.producName = productName3; rf.ShowDialog(); Config.NewKeyValue("isDemo", 0); if (rf.DialogResult == DialogResult.Cancel) { return; } } } else { Config.NewKeyValue("isDemo", 0); Config.NewKeyValue("CompanyName", Company); Config.NewKeyValue("SoftType", SoftType); Config.NewKeyValue("isOnline", isOnline); } if (isOnline == 0) // Trường hợp off line { if (created == "0") // { CreateData frmCreateData = new CreateData(productName3); frmCreateData.ShowDialog(); if (frmCreateData.DialogResult == DialogResult.Cancel) { return; } Registry.SetValue(P_KEY2, "Created", 1); } } else { CPUid cpu = new CPUid(productName3); UserConnection u = new UserConnection(); u.DatabaseName = productName3; u.ComputerName = cpu.MaMay; u.LicenceKey = "";// Registry.GetValue(P_KEY2, "EBA4330AABE2029DB278B8A049E33A07", ""); ; string ob = JsonConvert.SerializeObject(u); string re = GetConnection(ob); try { u = JsonConvert.DeserializeObject <UserConnection>(re); if (u != null) { string structName = Registry.GetValue(P_KEY2, "StructName", "").ToString(); string connection = Security.DeCode64(u.StructDb); connection += ";Database=" + structName; Config.NewKeyValue("StructConnection", Security.EnCode64(connection)); if (DateTime.Now > u.TimeEx) { MessageBox.Show("Máy bạn đã hết hạn sử dụng gói phần mềm này!"); return; } } } catch { } } SetEnvironment(); Login frmLogin = new Login(); frmLogin.ShowDialog(); if (frmLogin.DialogResult != DialogResult.Cancel) { if (isOnline == 1)//Kiểm tra ngày hết hạn { try { //CDTControl.Log log = new CDTControl.Log(); //string uKey = log.GetExDate(RegisterNumber); //UserKey key = JsonConvert.DeserializeObject<UserKey>(uKey); //DateTime Exdate = key.Exdate; //if (DateTime.Now > Exdate) // MessageBox.Show("Máy bạn đã hết hạn sử dụng gói phần mềm này!"); } catch { } } Application.Run(new Main(frmLogin.drUser, frmLogin.drPackage)); } }