private void button1_Click(object sender, EventArgs e) { bool conflict = false; for (int i = 0; i < monthCalendar1.BoldedDates.Count(); i++) { if (monthCalendar1.BoldedDates[i] >= monthCalendar1.SelectionStart && monthCalendar1.BoldedDates[i] <= monthCalendar1.SelectionEnd) { conflict = true; break; } } if (conflict) { MessageBox.Show("The tool K" + tools1.SelectedTool.K_number.ToString() + " is not available in this period.", "Error", MessageBoxButtons.OK); this.DialogResult = System.Windows.Forms.DialogResult.None; } else { using (var hobbyklub = new HobbyKlubEntities1()) { hobbyklub.Location.AddObject(new Location() { MemberId = MyMember.MemberId, StartDate = monthCalendar1.SelectionStart, EndDate = monthCalendar1.SelectionEnd, Status = (int)Status.Reserveret, ToolId = tools1.SelectedTool.ToolId }); hobbyklub.SaveChanges(); } } }
private void okButton_Click(object sender, EventArgs e) { using (var db = new HobbyKlubEntities1()) { if (member != null) { db.Member.Attach(member); } else { member = new Member(); db.Member.AddObject(member); } member.Address = address.Text; member.Email1 = mail.Text; member.PhoneMobile = mobile.Text; member.Name = name.Text; db.SaveChanges(); int xxx = 0; } DialogResult = System.Windows.Forms.DialogResult.OK; }
public void LoadData() { if (DesignMode) return; using (var hk = new HobbyKlubEntities1()) { members = hk.Member.ToList(); } comboBox1.Items.Clear(); comboBox1.Items.AddRange(members.Select(x => x.Name).ToArray()); }
private void button1_Click(object sender, EventArgs e) { bool conflict = false; for (int i = 0; i < monthCalendar1.BoldedDates.Count(); i++) { if (monthCalendar1.BoldedDates[i] >= monthCalendar1.SelectionStart && monthCalendar1.BoldedDates[i] <= monthCalendar1.SelectionEnd) { conflict = true; break; } } if (conflict) { MessageBox.Show("The tool K" + tools1.SelectedTool.K_number.ToString() + " is not available in this period.", "Error", MessageBoxButtons.OK); this.DialogResult = System.Windows.Forms.DialogResult.None; } else { using (var db = new HobbyKlubEntities1()) { var rv = db.Location.Where(x => x.MemberId == MyMember.MemberId && x.ToolId == MyTool.ToolId && x.Status == (int)Status.Reserveret); if (rv.Count() > 0) { //foreach (var loc in rv) //{ var loc = rv.First(); // convert only first reservation to udlejninger, normally there should only be one db.Location.Attach(loc); loc.Status = (int)Status.Udlejet; loc.StartDate = monthCalendar1.SelectionStart; loc.EndDate = monthCalendar1.SelectionEnd; // break; //} db.SaveChanges(); } else { db.Location.AddObject(new Location() { MemberId = MyMember.MemberId, StartDate = monthCalendar1.SelectionStart, EndDate = monthCalendar1.SelectionEnd, Status = (int)Status.Udlejet, ToolId = tools1.SelectedTool.ToolId }); db.SaveChanges(); } } } }
private void tools1_OnToolSelected(Tool obj) { using (var db = new HobbyKlubEntities1()) { var rv = db.Location.Where(x => x.ToolId == tools1.SelectedTool.ToolId && x.Status > (int)Status.Afleveret && x.EndDate >= DateTime.Now); foreach (var loc in rv) // mark all days where the tool is not available { DateTime start = (DateTime)loc.StartDate; DateTime end = (DateTime)loc.EndDate; for (DateTime l = start; l <= end; l = l.AddDays(1)) { monthCalendar1.AddBoldedDate(l); } } monthCalendar1.UpdateBoldedDates(); locationListOfSelectedTool = rv.ToList(); listBox1.Items.Clear(); listBox1.Items.AddRange(locationListOfSelectedTool.Select(x => x.StartDate.ToShortDateString() + " ... " + x.EndDate.ToString().Substring(0, 8) + "\t" + x.Member.Name + "\t" + ((Status)x.Status).ToString()).ToArray()); } }
private void button1_Click(object sender, EventArgs e) { using (var db = new HobbyKlubEntities1()) { var rv = db.Location.Where(x => x.MemberId == MyMember.MemberId && x.ToolId == MyTool.ToolId && x.Status == (int)Status.Udlejet); if (rv.Count() > 0) { //foreach (var loc in rv) //{ var loc = rv.First(); // convert only first reservation to udlejninger, normally there should only be one db.Location.Attach(loc); loc.Status = (int)Status.Afleveret; loc.EndDate = dateTimePicker1.Value; // break; //} db.SaveChanges(); } else { MessageBox.Show("Member " + MyMember.Name + " does not have tool " + MyTool.Name + " K" + MyTool.K_number.ToString()); } } }
private void ShowUdlejninger() { using (var db = new HobbyKlubEntities1()) { if (memberDropDown1.SelectedMember != null) { var rv = db.Location.Where(x => x.MemberId == memberDropDown1.SelectedMember.MemberId && x.Status == (int)Status.Udlejet).OrderBy(x => x.StartDate); //available.TraceQuery(); udlejningsList = rv.ToList(); listBox2.Items.Clear(); listBox2.Items.AddRange(udlejningsList.Select(x => x.StartDate.ToShortDateString() + " ... " + x.EndDate.ToString().Substring(0, 8) + "\t" + x.Tool.Name + " K" + x.Tool.K_number.ToString()).ToArray()); } else { var rv = db.Location.Where(x => x.MemberId > 0 && x.Status == (int)Status.Udlejet).OrderBy(x => x.StartDate); //available.TraceQuery(); udlejningsList = rv.ToList(); listBox2.Items.Clear(); listBox2.Items.AddRange(udlejningsList.Select(x => x.StartDate.ToShortDateString() + " ... " + x.EndDate.ToString().Substring(0, 8) + "\t" + x.Tool.Name + " K" + x.Tool.K_number.ToString() + "\t" + x.Member.Name).ToArray()); } } }