public void InsertNewItem() { NHibernateRepository repo = new NHibernateRepository(); int oldCount = repo.Query <Item>().Count; var item2 = new Item() { asset = "3143", campusCode = 8, description = "This is a good one", bldg = "332-00445", room = "312B", otherLocation = "otherlocation", acqDate = new DateTime(2008, 8, 29), totalCost = Convert.ToDecimal(330044.04), Model = "Model", serialNumber = "FFF00000422", isDelete = false, comments = "comments", }; IList <Staff> st = repo.Query <Staff>(); item2.Staffs = st[0]; repo.SaveOrUpdate(item2); Assert.AreEqual(repo.Query <Item>().Count, oldCount + 1); }
protected void InsertTestEntity(string name) { var testEntityRepository = new NHibernateRepository<TestEntity>(); var testEntity = new TestEntity { Name = name }; testEntityRepository.SaveOrUpdate(testEntity); NHibernateSession.Current.Evict(testEntity); }
private void Addbtn_Click(object sender, EventArgs e) { Staff newStaff = new Staff(); if (firstNametextBox.Text != "" && lastNametextBox.Text != "" && groupCodetextBox.Text != "") { ICriterion criterion = Expression.Eq("groupCode", groupCodetextBox.Text); IList <Staff> testExistSameGroupCode = repo.Query <Staff>(criterion); if (testExistSameGroupCode.Count == 0) { newStaff.firstName = firstNametextBox.Text; newStaff.lastName = lastNametextBox.Text; newStaff.groupCode = groupCodetextBox.Text; } else { MessageBox.Show("this groupCode is used, you can't use this groupCode"); return; } } else { MessageBox.Show("Please check what you entered!"); return; } //do we need to check format??????????? if (phonetextBox.Text != "") { newStaff.phone = phonetextBox.Text; } if (emailtextBox.Text != "") { newStaff.email = emailtextBox.Text; } if (locationtextBox.Text != "") { newStaff.location = locationtextBox.Text; } repo.SaveOrUpdate(newStaff); this.DialogResult = DialogResult.OK; this.Close(); return; }
protected void InsertTestEntity(string name) { var testEntityRepository = new NHibernateRepository <TestEntity>(); var testEntity = new TestEntity { Name = name }; testEntityRepository.SaveOrUpdate(testEntity); NHibernateSession.Current.Evict(testEntity); }
public void CanReturnSingleRecentItem() { // save a prod var ciRep = new NHibernateRepository<CharityInfo>(); var ci = new CharityInfo(); ci.CharityName = "testprod"; ciRep.SaveOrUpdate(ci); int savedId = ci.Id; this.FlushSessionAndEvict(ci); var ciRep2 = new NHibernateRepository<CharityInfo>(); var foundProd = ciRep2.Get(savedId); Assert.AreEqual("testprod", foundProd.CharityName); }
public void TestConnection() { var staff = new Staff() { groupCode = "GroupCode", lastName = "11Hello", firstName = "22World", email = "*****@*****.**", phone = "979979979", location = "HRBBf" }; NHibernateRepository repo = new NHibernateRepository(); //repo.DeleteByQuery("from Staff s"); repo.SaveOrUpdate(staff); Assert.AreEqual(repo.Query <Staff>().Count, 1); }
private void UpdateBtn_Click(object sender, EventArgs e) { if (passwordtextBox.Text != confirmPasswordtextBox.Text) { MessageBox.Show("Please make sure the passwords are the same"); return; } else { user.Password = passwordtextBox.Text; } NHibernateRepository repo = new NHibernateRepository(); repo.SaveOrUpdate(user); this.DialogResult = DialogResult.OK; this.Close(); return; }
private void Addbtn_Click(object sender, EventArgs e) { //NHibernateRepository repo = new NHibernateRepository(); Item item = new Item(); string staffName = staffcomboBox.SelectedItem.ToString(); { char[] ch = new char[staffName.Length]; ch = staffName.ToCharArray(); int i; for (i = 0; i < staffName.Length; i++) { if (ch[i] == ',') { break; } } string lastName = staffName.Substring(0, i); string firstName = staffName.Substring(i + 1, staffName.Length - i - 1); ICriterion[] expressions = new ICriterion[2]; expressions[0] = Expression.Like("firstName", "%" + firstName + "%"); expressions[1] = Expression.Like("lastName", "%" + lastName + "%"); IList <Staff> st = repo.Query <Staff>(expressions); item.Staffs = st[0]; item.firstName = item.Staffs.firstName; item.lastName = item.Staffs.lastName; item.groupCode = item.Staffs.lastName; } if (assettextBox.Text != "" && bldgtextBox.Text != "" && campusCodetextBox.Text != "" && roomtextBox.Text != "" && costtextBox.Text != "" && descriptiontextBox.Text != "" && validateInteger(campusCodetextBox.Text)) { item.asset = assettextBox.Text; item.bldg = bldgtextBox.Text; item.campusCode = Convert.ToInt32(campusCodetextBox.Text); item.room = roomtextBox.Text; decimal cost; if (Decimal.TryParse(costtextBox.Text, out cost)) { item.totalCost = cost; } else { MessageBox.Show("Please check your totalCost blank!"); return; } item.description = descriptiontextBox.Text; } else { MessageBox.Show("Please check what you entered!"); return; } item.acqDate = dateTimePicker.Value; if (modeltextBox.Text != "") { item.Model = modeltextBox.Text; } if (otherLocationtextBox.Text != "") { item.otherLocation = otherLocationtextBox.Text; } if (serialNumbertextBox.Text != "") { item.serialNumber = serialNumbertextBox.Text; } if (commentstextBox.Text != "") { item.comments = commentstextBox.Text; } if (pic != null) { item.picture = pic; } item.isDelete = false; item.isChecked = false; repo.SaveOrUpdate(item); this.DialogResult = DialogResult.OK; this.Close(); return; }
public void InsertStaffAndItem() { var staff1 = new Staff() { groupCode = "Codde", lastName = "22shi", firstName = "11wei", email = "*****@*****.**", phone = "119798989987", location = "1HRBB" }; byte[] bytes = { 201, 209 }; var item1 = new Item() { asset = "134410", campusCode = 78, description = "This is a good one", bldg = "02-00445", room = "312B", otherLocation = "otherlocation", acqDate = new DateTime(2008, 8, 29), totalCost = Convert.ToDecimal(330044.04), Model = "Model", serialNumber = "FFF00000422", groupCode = staff1.groupCode, lastName = staff1.lastName, firstName = staff1.firstName, isDelete = false, comments = "comments", picture = bytes, }; var item2 = new Item() { asset = "3143", campusCode = 18, description = "This is a good one", bldg = "332-00445", room = "312B", otherLocation = "otherlocation", acqDate = new DateTime(2008, 8, 29), totalCost = Convert.ToDecimal(330044.04), Model = "Model", serialNumber = "FFF00000422", groupCode = staff1.groupCode, lastName = staff1.lastName, firstName = staff1.firstName, isDelete = false, comments = "comments", picture = bytes, }; //staff1.Items = new HashSet<Item> { item1 }; item1.Staffs = staff1; item2.Staffs = staff1; NHibernateRepository repo = new NHibernateRepository(); //repo.DeleteByQuery("from Item a"); //object id = repo.Insert(staff1); //repo.DeleteByQuery("from Staff s"); //repo.DeleteByQuery("from Item t"); repo.SaveOrUpdate(staff1); //IList<Staff> st = repo.Query<Staff>(); //var tt = st[0]; repo.SaveOrUpdate(item2); //Restrictions.Like("Firstname", "YJing%") //InventoryApp.Common.NHibernateRepository.ICriterion criterion = new ICriterion(); //NHibernate.Criterion.ICriterion expr //System.Collections.IList it = repo.QueryBySQL("select * from item,staff where staff.groupCode = item.groupCode "); IList <Staff> st = repo.Query <Staff>("from Staff a where a.groupCode = 'Codde' "); Assert.AreEqual(repo.Query <Staff>().Count, 1); }
private Tuple<int, int> MakeSomeData(int howMany) { int firstId = -1; int lastId = -1; var ciRep = new NHibernateRepository<CharityInfo>(); for (int i = 0; i <= howMany; i++) { var ci = new CharityInfo(); ci.CharityName = "testprod"+ i.ToString(); ciRep.SaveOrUpdate(ci); if (firstId == -1) firstId = ci.Id; if (i == howMany) lastId = ci.Id; this.FlushSessionAndEvict(ci); } return new Tuple<int, int>(firstId, lastId); }