private void btnOk_Click(object sender, EventArgs e) { if (Validation()) { try { this.Details.BirthDate = new DateTime(Convert.ToInt32(tbYear.Text), cbMonth.SelectedIndex + 1, Convert.ToInt32(tbDay.Text)); } catch { this.Details.BirthDate = DateTime.Now; } try { this.Details.DocumentId = ((Lib.ServiceFunctions.ListItem)cbDocumentType.SelectedItem).ID; this.Details.DocumentNumber = tbDocumentNumber.Text; } catch { this.Details.DocumentId = 0; } this.Details.FIO = tbFIO.Text; if (this.Details.FIO == "") { this.Details.FIO = "Разовый"; } this.Details.Phone = tbPhone.Text; this.Details.RegisterDate = Convert.ToDateTime(tbRegisterDate.Text); this.Details.SourceId = ((Lib.ServiceFunctions.ListItem)cbSource.SelectedItem).ID; this.Details.TypeId = ((Lib.ServiceFunctions.ListItem)cbClientType.SelectedItem).ID; this.Details.Sex = cbSex.SelectedIndex; if (this.Id == 0) { this.Details.Barcode = Lib.ServiceFunctions.ScanPrefix() + tbCode.Text; this.Id = DBLayer.Clients.Insert(this.Details); try { for (int i = 0; i < Abonements.Count; i++) { DBLayer.ClientsAbonements.ClientsAbonements_WideDetails det = (DBLayer.ClientsAbonements.ClientsAbonements_WideDetails)Abonements[i]; DBLayer.ClientsAbonements.Details caDet = new FitnessProject.DBLayer.ClientsAbonements.Details(); DBLayer.Abonements.Details aDet = DBLayer.Abonements.GetDetails(det.AbonementId); if (aDet.LessonsCount != 0) { caDet.VisitsCount = aDet.LessonsCount; } if (aDet.AdditionalVisits != 0) { caDet.AdditionalCount = aDet.AdditionalVisits; } caDet.AbonementId = det.AbonementId; caDet.ClientId = this.Id; caDet.DateFinish = det.DateFinish; caDet.DateStart = det.DateStart; caDet.CoachId = det.CoachId; caDet.Weekdays = det.Weekdays; caDet.Time = det.Time; int caId = DBLayer.ClientsAbonements.Insert(caDet); if (MessageBox.Show(this, "Провести платеж " + DBLayer.Abonements.GetDetails(caDet.AbonementId).Cost.ToString() + "?", Lib.StringConstants.ProjectName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DBLayer.AbonementIncome.Details detAI = new FitnessProject.DBLayer.AbonementIncome.Details(); detAI.ClientAbonementId = caId; detAI.AbonementId = caDet.AbonementId; detAI.ClientId = caDet.ClientId; detAI.Date = DateTime.Now.Date; detAI.Summ = DBLayer.Abonements.GetDetails(caDet.AbonementId).Cost; detAI.UserId = ((DBLayer.Users.Details)AppDomain.CurrentDomain.GetData("User")).Id; DBLayer.AbonementIncome.Insert(detAI); } } //MessageBox.Show(this.photo.Length.ToString()); try { if (this.photo.Length > 0) { DBLayer.Clients.UploadPhoto(this.photo, this.Id); } } catch { DBLayer.Clients.RemovePhoto(this.Id); } } catch { } if (MessageBox.Show(this, "Провести клиента в зал?", Lib.StringConstants.ProjectName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { SimulateSelectClient(); } } else { if (this.BarcodeChanged) { this.Details.Barcode = Lib.ServiceFunctions.ScanPrefix() + tbCode.Text; this.BarcodeChanged = false; } else { this.Details.Barcode = tbCode.Text; } DBLayer.Clients.Update(this.Details); //MessageBox.Show(this.photo.Length.ToString()); try { if (this.photo.Length > 0) { DBLayer.Clients.UploadPhoto(this.photo, this.Id); } //else // DBLayer.Clients.RemovePhoto(this.Id); } catch { //DBLayer.Clients.RemovePhoto(this.Id); } } this.Close(); } }
private void btnOk_Click(object sender, EventArgs e) { if (this.AbonementId == 0) { MessageBox.Show(this, "Не указан абонемент!", Lib.StringConstants.ProjectName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int a = 0; if (this.Id == 0) { if (this.Details.Id == 0) { SimulateSelectAbonement(); } else { this.CADetails.AbonementId = this.AbonementId; DBLayer.Abonements.Details aDet = DBLayer.Abonements.GetDetails(this.CADetails.AbonementId); this.CADetails.DateStart = Convert.ToDateTime(tbStartDate.Text); this.CADetails.DateFinish = Convert.ToDateTime(tbFinishDate.Text); this.CADetails.ClientId = this.Details.Id; if (cbCoach.SelectedItem != null) { this.CADetails.CoachId = ((Lib.ServiceFunctions.ListItem)cbCoach.SelectedItem).ID; } this.CADetails.Time = tbTime.Text; this.CADetails.Weekdays = tbWeekdays.Text; if (aDet.LessonsCount != 0) { this.CADetails.VisitsCount = aDet.LessonsCount; } if (aDet.AdditionalVisits != 0) { this.CADetails.AdditionalCount = aDet.AdditionalVisits; } if (aDet.LessonsCount != 0) { this.CADetails.VisitsCount = aDet.LessonsCount; } if (aDet.AdditionalVisits != 0) { this.CADetails.AdditionalCount = aDet.AdditionalVisits; } if (MessageBox.Show(this, "Провести платеж - " + aDet.Cost.ToString() + "?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int caId = DBLayer.ClientsAbonements.Insert(this.CADetails); DBLayer.AbonementIncome.Details det = new FitnessProject.DBLayer.AbonementIncome.Details(); DBLayer.Users.Details uDet = (DBLayer.Users.Details)AppDomain.CurrentDomain.GetData("User"); det.AbonementId = this.CADetails.AbonementId; det.ClientId = this.CADetails.ClientId; det.Date = DateTime.Now.Date; det.Summ = aDet.Cost; det.UserId = uDet.Id; det.ClientAbonementId = caId; DBLayer.AbonementIncome.Insert(det); } this.Close(); } } else { this.CADetails.AbonementId = this.AbonementId; this.CADetails.DateStart = Convert.ToDateTime(tbStartDate.Text); this.CADetails.DateFinish = Convert.ToDateTime(tbFinishDate.Text); if (cbCoach.SelectedItem != null) { this.CADetails.CoachId = ((Lib.ServiceFunctions.ListItem)cbCoach.SelectedItem).ID; } this.CADetails.Time = tbTime.Text; this.CADetails.Weekdays = tbWeekdays.Text; DBLayer.ClientsAbonements.Update(this.CADetails); this.Close(); } }