public int InsertAreas(Pack p) { IList<long> list = p.Areas; if(list == null || list.Length == 0) return 0; int inserted = 0; DbModel model = new DbModel("PackArea", null); for(int i = 0; i < list.Length; i++) inserted += (model.Insert(p.Id, list[i]) ? 1 : 0); return inserted; }
private void DoOk(object sender, EventArgs args) { Member m = new Member(); m.Id = this.CurrentClient.Id; m.Sync(); MemberModel mm = new MemberModel(); if(m.Active != this.ActiveCheck.Active) mm.Update(m, "Active", this.ActiveCheck.Active); if(this.ImageToSave != null && this.ImageToSave.Length != m.BinImage.Length) { m.BinImage = this.ImageToSave; mm.SetImage(m); } if(m.Weight != this.WeightSpin.Value) mm.Update(m, "Weight", this.WeightSpin.Value); if(m.Height != this.HeightSpin.Value) mm.Update(m, "Height", this.HeightSpin.Value); char ctrl_gender = this.GenderCombo.Active == 0 ? 'm' : 'f'; if(m.Gender != ctrl_gender) mm.Update(m, "Gender", ctrl_gender); if(m.BirthDate.CompareTo(this.BirthdayWidget.Date) != 0) mm.Update(m, "BirthDate", this.BirthdayWidget.Date.ToString("yyyy-MM-dd")); if(m.InnerContact.Id == 0 && !string.IsNullOrEmpty(this.ContactNameEntry.Text.Trim() + this.ContactPhoneEntry.Text.Trim())) { DbModel model = new DbModel("Contact"); model.Insert(null, this.ContactNameEntry.Text.Trim(), this.ContactPhoneEntry.Text.Trim()); long last = model.LastInsertId; mm.Update(m, "Contact", last); } else if(m.InnerContact.Name != this.ContactNameEntry.Text || m.InnerContact.PhoneNumber != this.ContactPhoneEntry.Text) { DbModel model = new DbModel("Contact"); model.UpdateById(m.InnerContact.Id, "Name", this.ContactNameEntry.Text.Trim()); model.UpdateById(m.InnerContact.Id, "PhoneNumber", this.ContactPhoneEntry.Text.Trim()); } Client c = m.InnerClient; ClientModel cm = new ClientModel(); if(c.Name != this.NameEntry.Text) cm.Update(c, "Name", this.NameEntry.Text.Trim()); if(c.Surname != this.SurnameEntry.Text) cm.Update(c, "Surname", this.SurnameEntry.Text.Trim()); if(c.Address != this.AddressEntry.Text) cm.Update(c, "Address", this.AddressEntry.Text.Trim()); omarkhd.Validation.Validator v = new omarkhd.Validation.Validator(); v.SetRule(this.PhoneEntry.Text, "phone", omarkhd.Validation.ValidationRule.Natural); if(c.PhoneNumber != this.PhoneEntry.Text && v.Run().Status) cm.Update(c, "PhoneNumber", this.PhoneEntry.Text.Trim()); v = new omarkhd.Validation.Validator(); v.SetRule(this.EmailEntry.Text, "email", omarkhd.Validation.ValidationRule.Email); if(c.Email != this.EmailEntry.Text && v.Run().Status) cm.Update(c, "Email", this.EmailEntry.Text.Trim()); this.DoCancel(null, null); }
private void NewEnrollment(object sender, EventArgs args) { MemberWizard ww = new MemberWizard(); ww.SuccessEvent += (object o) => { Member m = (Member) o; Client c = m.InnerClient; ClientModel cm = new ClientModel(); MemberModel mm = new MemberModel(); ///adding the new client if needed if(c.Id == -1) //-1 = new client { cm.Insert(c); c.Id = cm.LastInsertId; } //add the contact info if(m.InnerContact.Name.Length > 0) { DbModel contact_m = new DbModel("Contact"); contact_m.Insert(null, m.InnerContact.Name, m.InnerContact.PhoneNumber); m.InnerContact.Id = contact_m.LastInsertId; } //adding the member m.Id = c.Id; mm.Insert(m); //adding the membership debt if(m.ChargeMembership) { DbModel mship_m = new DbModel("MembershipDebt"); mship_m.Insert(m.Id, null); } PaymentRuler.ChargeFirstMonth(m); }; ww.Run(); }