public static bool isBiggerName(string value1, string value2) { value1 = TPerson.CheckNameString(value1).ToLower(); value2 = TPerson.CheckNameString(value2).ToLower(); for (int i = 0; i < biggerInt(value1.Length, value2.Length); i++) { if (i == value1.Length && i < value2.Length) { return(false); } if (i < value1.Length && i == value2.Length) { return(true); } if (findIndex(Statics.alphabet, value1.ToCharArray()[i]) > findIndex(Statics.alphabet, value2.ToCharArray()[i])) { return(true); } if (findIndex(Statics.alphabet, value1.ToCharArray()[i]) < findIndex(Statics.alphabet, value2.ToCharArray()[i])) { return(false); } } return(false); }
public IActionResult PersonsTable(string surname = "", string name1 = "", string name2 = "") { var personDB = _db.TPerson.FromSqlInterpolated($"SELECT * FROM t_person").ToList(); List <TPerson> info = new List <TPerson>(); foreach (var a in personDB) { TPerson r = new TPerson(); r.IdPerson = a.IdPerson; r.Surname = a.Surname; r.Name1 = a.Name1; r.Name2 = a.Name2; r.PhonePerson = a.PhonePerson; r.EmailP = a.EmailP; r.PhotoP = a.PhotoP; if (surname != "" && surname != null && surname != r.Surname) { continue; } if (name1 != "" && name1 != null && name1 != r.Name1) { continue; } if (name2 != "" && name2 != null && name2 != r.Name2) { continue; } info.Add(r); } return(View(info)); }
public static bool DelWorkerRole(int id) { using (MainDataContext dbContext = new MainDataContext()) { using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { try { B_WORKER_ROLE wr = dbContext.B_WORKER_ROLE.SingleOrDefault(t => t.ID == id); dbContext.B_WORKER_ROLE.DeleteOnSubmit(wr); //同步Tperson if (!string.IsNullOrEmpty(wr.TPerson编码)) { TPerson tp = dsContext.TPerson.SingleOrDefault(t => t.编码 == wr.TPerson编码); dsContext.TPerson.DeleteOnSubmit(tp); } dbContext.SubmitChanges(); dsContext.SubmitChanges(); return(true); } catch (Exception ex) { Log4Net.LogError("DelWorkerRole", ex.ToString()); return(false); } } } }
public IActionResult RelationRP(string corp = "", string n = "") { ForRltn info = new ForRltn(); List <TPerson> lst = new List <TPerson>(); info.Pavilion = corp; info.Number = n; var personsDB = _db.TPerson.FromSqlInterpolated($"SELECT * FROM t_person").ToList(); foreach (var a in personsDB) { TPerson r = new TPerson(); r.IdPerson = a.IdPerson; r.Surname = a.Surname; r.Name1 = a.Name1 != null ? a.Name1 : ""; r.Name2 = a.Name2 != null ? a.Name2 : ""; r.PhonePerson = a.PhonePerson != null ? a.PhonePerson : ""; r.EmailP = a.EmailP != null ? a.EmailP : ""; r.PhotoP = a.PhotoP != null ? a.PhotoP : ""; lst.Add(r); // info.Persons.Add(r); } info.Persons = lst; return(View(info)); }
private List <object> CreatePersonAndDetails <TPerson, TDetails>() where TPerson : Person, new() where TDetails : Details, new() { List <object> ids = new List <object>(); using (ISession s = Sfi.OpenSession()) using (ITransaction tx = s.BeginTransaction()) { for (int i = 0; i < 6; i++) { Person person = new TPerson(); if (i % 2 == 0) { Details details = new TDetails(); details.Data = String.Format("{0}{1}", typeof(TDetails).Name, i); person.Details = details; } person.Name = String.Format("{0}{1}", typeof(TPerson).Name, i); ids.Add(s.Save(person)); } tx.Commit(); } return(ids); }
public static bool Delete(IList <string> listId) { using (MainDataContext dbContext = new MainDataContext()) { using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { try { //删除Tperson foreach (string id in listId) { int workerId = int.Parse(id); List <B_WORKER_ROLE> listWorkerRole = dbContext.B_WORKER_ROLE.Where(t => t.WorkerID == workerId && t.TPerson编码 != null && t.TPerson编码 != "").ToList(); foreach (B_WORKER_ROLE workerRole in listWorkerRole) { TPerson person = dsContext.TPerson.FirstOrDefault(t => t.编码 == workerRole.TPerson编码); dsContext.TPerson.DeleteOnSubmit(person); } } dsContext.SubmitChanges(); //删除人员 StringBuilder sb = new StringBuilder(); sb.Append("SET XACT_ABORT ON "); sb.AppendLine(" BEGIN TRAN "); foreach (string id in listId) { int workerId = int.Parse(id); //删除人员 sb.AppendFormat(" delete B_WORKER where id={0}", workerId); //删除人员组织 sb.AppendFormat(" delete B_WORKER_ORGANIZATION where WorkerID={0}", workerId); //删除人员角色 sb.AppendFormat(" delete B_WORKER_ROLE where WorkerID={0}", workerId); } sb.AppendLine(" COMMIT TRAN "); dbContext.ExecuteCommand(sb.ToString()); return(true); } catch (Exception ex) { Log4Net.LogError("删除人员", ex.Message); return(false); } } } }
public bool AddPerson(TPerson p) { try { _personRepository.Insert(p); } catch (Exception ex) { return(false); } return(true); }
public bool EditPerson(TPerson p) { try { _personRepository.Update(p); } catch (Exception ex) { return(false); } return(true); }
public bool DeletePerson(TPerson p) { try { _personRepository.Delete(p); } catch (Exception) { return(false); } return(true); }
/// <summary> /// 暂不进行数据库操作(只修改对象) 分块修改对象 更灵活 提高效率 /// </summary> public static TTaskPersonLink InsertTaskPerson(string TaskCode, string PersonCode) { TTaskPersonLink info = new TTaskPersonLink(); TPerson perInfo = Person.GetOnePerson(PersonCode); info.任务编码 = TaskCode; info.人员编码 = perInfo.编码; info.姓名 = perInfo.姓名; info.分站编码 = perInfo.分站编码; info.是否有效 = perInfo.是否有效; info.人员类型编码 = perInfo.类型编码; return(info); //return m_DAL.InsertTaskPerson(info); }
private void button1_Click_1(object sender, EventArgs e) { if (radioButton1.Checked) { resp = new TStud("Петров", "Петр", 10000000, Convert.ToDateTime("12.01.2000"), 3.6); } if (radioButton2.Checked) { resp = new TProf("Рыков", "Игнат", 110000, "высшая", "информатика"); } textBox5.AppendText(resp.info() + "\n"); }
private void OneToOneUpdateTest <TPerson, TDetails>() where TPerson : Person, new() where TDetails : Details, new() { List <object> ids = this.CreatePersonAndDetails <TPerson, TDetails>(); IStatistics statistics = Sfi.Statistics; // Clear the second level cache and the statistics Sfi.EvictEntity(typeof(TPerson).FullName); Sfi.EvictEntity(typeof(TDetails).FullName); Sfi.EvictQueries(); statistics.Clear(); // Fill the empty caches with data. this.FetchPeopleById <TPerson>(ids); // Verify that no data was retrieved from the cache. Assert.AreEqual(0, statistics.SecondLevelCacheHitCount, "Second level cache hit count"); statistics.Clear(); int personId = DeleteDetailsFromFirstPerson <TPerson>(); // Verify that the cache was updated Assert.AreEqual(1, statistics.SecondLevelCachePutCount, "Second level cache put count"); statistics.Clear(); // Verify that the Person was updated in the cache using (ISession s = Sfi.OpenSession()) using (ITransaction tx = s.BeginTransaction()) { TPerson person = s.Get <TPerson>(personId); Assert.IsNull(person.Details); } Assert.AreEqual(0, statistics.SecondLevelCacheMissCount, "Second level cache miss count"); statistics.Clear(); // Verify that the Details was removed from the cache and deleted. using (ISession s = Sfi.OpenSession()) using (ITransaction tx = s.BeginTransaction()) { TDetails details = s.Get <TDetails>(personId); Assert.Null(details); } Assert.AreEqual(0, statistics.SecondLevelCacheHitCount, "Second level cache hit count"); }
public static bool IsExistEmpNo(string empNo) { using (MainDataContext dbContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { TPerson person = dbContext.TPerson.FirstOrDefault(t => t.工号 == empNo); if (person == null) { return(false); } else { return(true); } } }
public ActionResult GetEmpNoAndPassWord() { string workerId = User.Identity.Name.Split('|')[0]; string empNo = string.Empty; string passWord = string.Empty; Worker worker = new Worker(); int result; if (int.TryParse(User.Identity.Name.Split('|')[2], out result)) { string loginName = User.Identity.Name.Split('|')[2]; TPerson person = worker.GetTPerson(int.Parse(workerId), loginName); if (person != null) { empNo = person.工号; passWord = person.口令; } } else { List <B_WORKER_ROLE> listWorkerRole = worker.GetWorkerRole(int.Parse(workerId)); B_WORKER_ROLE wr = listWorkerRole.FirstOrDefault(t => !string.IsNullOrEmpty(t.EmpNo)); if (wr != null) { empNo = wr.EmpNo; } if (!string.IsNullOrEmpty(empNo)) { TPerson person = worker.GetTPersonByEmpNo(empNo); if (person != null) { passWord = person.口令; } } } return(Json(new { EmpNo = empNo, PassWord = passWord })); }
public static TPerson GetOnePerson(string personid) { TPerson personInfo = new TPerson(); try { using (MainDataContext dbContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { return(dbContext.TPerson.First(p => p.编码 == personid)); } } catch (Exception ex) { Log4Net.LogError("PersonDAL/GetOnePerson()", ex.ToString()); personInfo = null; } return(personInfo); }
public IActionResult Create(TPerson person, string actionType) { if (actionType == "Add") { if (ModelState.IsValid) { try{ _dbContext.TPersons.Add(person); _dbContext.SaveChanges(); } catch {} } else { return(View(person)); } } return(RedirectToAction("Index")); }
public IActionResult WritePerson(string id = null) { if (id == null || id == "") { TPerson inf0 = new TPerson(); return(View(inf0)); } var info_person = _db.TPerson.FromSqlInterpolated($"SELECT * FROM t_person WHERE id_person = {int.Parse(id)}").ToList(); TPerson inf = new TPerson(); inf.IdPerson = info_person[0].IdPerson; inf.Surname = info_person[0].Surname; inf.Name1 = info_person[0].Name1; inf.Name2 = info_person[0].Name2; inf.PhonePerson = info_person[0].PhonePerson; inf.EmailP = info_person[0].EmailP; return(View(inf)); }
public IActionResult Edit(TPerson person, string actionType) { if (actionType == "Update") { if (ModelState.IsValid) { try{ _dbContext.TPersons.Update(person); _dbContext.SaveChanges(); } catch {} } else { CreateViewBags(0); ViewData["panel"] = 1; return(View(person)); } } return(RedirectToAction("Index")); }
public static bool UpdatePassword(int workerId, string newPassword) { using (MainDataContext dbContext = new MainDataContext()) { using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { IApplicationContext ctx = ContextRegistry.GetContext(); IEncrypt encrypt = ctx["Encrypt"] as IEncrypt; B_WORKER worker = dbContext.B_WORKER.FirstOrDefault(v => v.ID == workerId); if (worker != null) { worker.PassWord = encrypt.Encrypt(workerId, newPassword); List <B_WORKER_ROLE> listWR = dbContext.B_WORKER_ROLE.Where(t => t.WorkerID == workerId).ToList(); foreach (B_WORKER_ROLE wr in listWR) { if (!string.IsNullOrEmpty(wr.EmpNo)) { TPerson tp = dsContext.TPerson.SingleOrDefault(t => t.工号 == wr.EmpNo); if (tp != null) { tp.口令 = new HashEncrypt().Encrypt(workerId, newPassword);; } } } } dbContext.SubmitChanges(); dsContext.SubmitChanges(); return(true); } } }
//public static List<C_ORGANIZE_TREE> GetWorkerTree(int id) //{ // using (MainDataContext dbContext = new MainDataContext()) // { // List<C_ORGANIZE_TREE> listTree = new List<C_ORGANIZE_TREE>(); // var list = from ra in dbContext.B_WORKER_ORGANIZATION // join r in dbContext.B_WORKER on ra.WorkerID equals r.ID // where ra.OrgID == id // select new // { // OrgID = ra.OrgID, // WorkerID = ra.WorkerID, // WorkerName = r.Name, // }; // foreach (var td in list) // { // C_ORGANIZE_TREE lw = new C_ORGANIZE_TREE(); // lw.id = td.WorkerID.ToString(); // lw.text = td.WorkerName; // lw.ParentID = td.OrgID.ToString(); // listTree.Add(lw); // } // return listTree; // } //} public static int Save(B_WORKER entity) { using (MainDataContext dbContext = new MainDataContext()) { using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { StringBuilder sb = new StringBuilder(); List <SqlParameter> paramArray = new List <SqlParameter>(); try { //人员 if (dbContext.B_WORKER.Count(t => t.ID == entity.ID) == 0) { //var list = from a in dbContext.B_WORKER select a.ID; //long total = list.LongCount(); //if (total == 0) //{ // entity.ID = 1; //} //else //{ // entity.ID = dbContext.B_WORKER.Max(a => a.ID) + 1; //} IApplicationContext ctx = ContextRegistry.GetContext(); IEncrypt encrypt = ctx["Encrypt"] as IEncrypt; entity.PassWord = encrypt.Encrypt(entity.ID, entity.PassWord); dbContext.B_WORKER.InsertOnSubmit(entity); } else { B_WORKER worker = dbContext.B_WORKER.Single(t => t.ID == entity.ID); worker.LoginName = entity.LoginName; worker.Name = entity.Name; worker.Sex = entity.Sex; worker.EntryDate = entity.EntryDate; worker.TitleTechnicalID = entity.TitleTechnicalID; worker.IsActive = entity.IsActive; worker.IsQuota = entity.IsQuota; worker.Mobile = entity.Mobile; worker.Tel = entity.Tel; worker.IsAllowInternetAccess = entity.IsAllowInternetAccess; worker.JobLevel = entity.JobLevel; } //调度台TPerson List <B_WORKER_ROLE> listWorkerRole = dbContext.B_WORKER_ROLE.Where(t => t.WorkerID == entity.ID && t.EmpNo != null && t.EmpNo != "").ToList(); foreach (B_WORKER_ROLE workerRole in listWorkerRole) { TPerson person = dsContext.TPerson.FirstOrDefault(t => t.工号 == workerRole.EmpNo); person.通话号码 = entity.Tel ?? string.Empty; person.短信号码 = entity.Mobile ?? string.Empty; person.是否有效 = entity.IsActive == "Y" ? true : false; person.姓名 = entity.Name; } dbContext.SubmitChanges(); dsContext.SubmitChanges(); return(entity.ID); } catch (Exception ex) { Log4Net.LogError("Save Worker", ex.Message); return(-1); } } } }
public static bool SaveWorkerRole(B_WORKER_ROLE entity) { using (MainDataContext dbContext = new MainDataContext()) { using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { try { //同步Tperson if (!string.IsNullOrEmpty(entity.EmpNo)) { B_WORKER worker = GetWorkerById(entity.WorkerID); B_ORGANIZATION unit = Organize.GetUnit(entity.OrgID); if (dsContext.TPerson.Count(t => t.编码 == entity.TPerson编码) == 0) { //string empNo = GetCoding(); IApplicationContext ctx = ContextRegistry.GetContext(); IEncrypt encrypt = ctx["Encrypt"] as IEncrypt; TPerson person = new TPerson(); person.编码 = entity.TPerson编码; person.单位编码 = unit.Type == (int)OrgType.Branch ? unit.编码 : "-1"; person.通话号码 = worker.Tel ?? string.Empty; person.短信号码 = worker.Mobile ?? string.Empty; person.分站编码 = unit.Type == (int)OrgType.Station ? unit.编码 : AppConfig.GetStringConfigValue("VirtualCode"); person.类型编码 = entity.RoleID; person.姓名 = worker.Name; person.工号 = entity.EmpNo; person.口令 = new HashEncrypt().DESEncrypt(encrypt.Decrypt(worker.PassWord), ""); person.次操作时间 = DateTime.Now; person.顺序号 = int.Parse(entity.TPerson编码); person.是否有效 = true; dsContext.TPerson.InsertOnSubmit(person); } else { var tp = dsContext.TPerson.FirstOrDefault(t => t.编码 == entity.TPerson编码); tp.单位编码 = unit.Type == (int)OrgType.Branch ? unit.编码 : "-1"; tp.分站编码 = unit.Type == (int)OrgType.Station ? unit.编码 : AppConfig.GetStringConfigValue("VirtualCode"); tp.类型编码 = entity.RoleID; tp.工号 = entity.EmpNo; } } //人员 if (entity.ID == 0) { var list = from a in dbContext.B_WORKER_ROLE select a.ID; long total = list.LongCount(); if (total == 0) { entity.ID = 1; } else { entity.ID = dbContext.B_WORKER_ROLE.Max(a => a.ID) + 1; } entity.EmpNo = entity.EmpNo ?? string.Empty; entity.TPerson编码 = entity.TPerson编码 ?? string.Empty; dbContext.B_WORKER_ROLE.InsertOnSubmit(entity); } else { var model = dbContext.B_WORKER_ROLE.FirstOrDefault(b => b.ID == entity.ID); model.OrgID = entity.OrgID; model.WorkerID = entity.WorkerID; model.RoleID = entity.RoleID; model.EmpNo = entity.EmpNo ?? string.Empty; model.ID = entity.ID; model.TPerson编码 = entity.TPerson编码 ?? string.Empty; } dbContext.SubmitChanges(); dsContext.SubmitChanges(); return(true); } catch (Exception ex) { Log4Net.LogError("SaveWorkerRole", ex.ToString()); return(false); } } } }
public void thrSimdiAktar() { for (int i = 0; i < rdr.Length; i++) { if (rdr[i].Connected) { for (int k = 0; k < (int)nmrKayit.Value; k++) { int iErr; uint InxNm; string CardID; CardID = randomString(); if (rdr[i].IsHex(CardID) && (CardID.Length == 14)) { TPerson Person = new TPerson(); Person.CardID = CardID; Person.Name = CardID; Person.Code = (uint)k; Person.Password = (ushort)0; Person.AccessDevice = true; Person.APBEnabled = true; Person.AccessCardEnabled = false; iErr = rdr[i].AddWhitelist(Person, out InxNm); switch (iErr) { case 0: addLog(i.ToString() + ". cihaza [" + rdr[i].IP.ToString() + "] Kişi eklendi."); break; case 1: addLog(i.ToString() + ". cihaza [" + rdr[i].IP.ToString() + "] Daha önce eklenmiş."); break; case 20: addLog(i.ToString() + ". cihaza [" + rdr[i].IP.ToString() + "] Şifre kapasitesi aşıldı."); break; case 51: addLog(i.ToString() + ". cihaza [" + rdr[i].IP.ToString() + "] Bu Kart ID daha önce tanımlanmış."); break; case 52: addLog(i.ToString() + ". cihaza [" + rdr[i].IP.ToString() + "] Bu şifre daha önce tanımlanmış."); break; default: addLog(i.ToString() + ". cihaza [" + rdr[i].IP.ToString() + "] Hata iErr : " + iErr.ToString()); break; } } } } else { addLog(i.ToString() + " . cihaza bağlantı yok. Tekrar deneyecek."); } } for (int l = 0; l < rdr.Length; l++) { rdr[l].DisConnect(); if (!rdr[l].Connected) { addLog(l.ToString() + " . Bağlantı başarıyla kesildi."); } } addLog("Sonlandı."); MessageBox.Show("İşlem tamamlandı."); }