public bool Login(string username, string password, eUserType userType, string ip, string mac, string hostname) { try { using (var context = new WinDbEntities()) { var i = context.Users.FirstOrDefault(u => u.Username == username && u.Password == password && u.Type == (byte)userType); if (i == null) { return(false); } i.LoginTraces.Add(new LoginTrace() { Hostname = hostname, IpAddress = ip, MacAddress = mac, TimeLogin = DateTime.Now }); context.SaveChanges(); return(true); } } catch (Exception ex) { Logger.Error(ex); return(false); } }
private void ImportScanAcc(byte serverType) { try { OpenFileDialog openFileDialog1 = new OpenFileDialog(); //openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "TXT files|*.txt"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = openFileDialog1.FileName; string[] filelines = File.ReadAllLines(filename); Dictionary <string, string> ibetAccdics = new Dictionary <string, string>(); foreach (var sboScanAcc in filelines) { var a = sboScanAcc.Split(new[] { "<>" }, StringSplitOptions.None); ibetAccdics[a[0]] = a[1]; } using (var context = new WinDbEntities()) { foreach (var o in ibetAccdics) { context.ScanAccounts.Add(new ScanAccount() { ServerType = serverType, Username = o.Key, Password = o.Value, IsBlock = false, IsFree = true, PassChangeVersion = 0 }); } context.SaveChanges(); } MessageBox.Show("DONE!"); } } catch (Exception ex) { Logger.Error(ex); MessageBox.Show("Lổi import data !"); } }
private void btnSubmit_Click(object sender, EventArgs e) { int getSbo = 0; int getIbet = 0; byte userType = (byte)(cbUserType.SelectedIndex + 1); if (userType == 1) { getSbo = (int)numSboScanAcc.Value; } else { getSbo = (int)numSboScanAcc.Value; getIbet = (int)numIbetScanAcc.Value; } if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("Invalid input user information!"); return; } try { using (var context = new WinDbEntities()) { User u = new User(); u.Username = txtUsername.Text; u.Password = txtPassword.Text; u.Type = userType; var sbo = context.ScanAccounts.OrderBy(x => Guid.NewGuid()).Where(s => !s.IsBlock && s.IsFree && s.ServerType == 2).Take(getSbo); foreach (var sba in sbo) { sba.IsFree = false; u.AccScanInUses.Add(new AccScanInUse { ScanAccount = sba }); } var ibetA = context.ScanAccounts.OrderBy(x => Guid.NewGuid()).Where(s => !s.IsBlock && s.IsFree && s.ServerType == 1).Take(getIbet); foreach (var ibe in ibetA) { ibe.IsFree = false; u.AccScanInUses.Add(new AccScanInUse() { ScanAccount = ibe }); } context.Users.Add(u); context.SaveChanges(); } MessageBox.Show("DONE!"); } catch (Exception ex) { Logger.Error(ex); MessageBox.Show("Add user fail!"); } }