private void butOK_Click(object sender, System.EventArgs e) { if (textPercent.errorProvider1.GetError(textPercent) != "" || textAmount.errorProvider1.GetError(textAmount) != "" || textQuantity.errorProvider1.GetError(textQuantity) != "" ) { MsgBox.Show(this, "Please fix data entry errors first."); return; } if (textProcCode.Text != "" && listCategory.SelectedIndex != 0) { MsgBox.Show(this, "If a procedure code is entered, category must be None."); return; } //not allowed to set to pat if editing plan only, and no patplanNum is available if (PatPlanNum == 0 && checkPat.Checked) { MsgBox.Show(this, "Not allowed to check the Pat box because no patient is available."); return; } if (listType.SelectedIndex != (int)InsBenefitType.CoInsurance && PIn.Long(textPercent.Text) != 0) { MsgBox.Show(this, "Not allowed to enter a percentage unless type is CoInsurance."); return; } if (textProcCode.Text != "" && ProcedureCodes.GetCodeNum(textProcCode.Text) == 0) { MsgBox.Show(this, "Invalid procedure code."); return; } if (checkPat.Checked) { BenCur.PatPlanNum = PatPlanNum; BenCur.PlanNum = 0; } else { BenCur.PatPlanNum = 0; BenCur.PlanNum = PlanNum; } if (listCategory.SelectedIndex == 0) { BenCur.CovCatNum = 0; } else { BenCur.CovCatNum = _listCovCats[listCategory.SelectedIndex - 1].CovCatNum; } BenCur.CodeNum = ProcedureCodes.GetCodeNum(textProcCode.Text); BenCur.BenefitType = (InsBenefitType)listType.SelectedIndex; if (textPercent.Text == "") { BenCur.Percent = -1; } else { BenCur.Percent = PIn.Int(textPercent.Text); } if (textAmount.Text == "") { BenCur.MonetaryAmt = -1; } else { BenCur.MonetaryAmt = PIn.Double(textAmount.Text); } /*if(isAnnualMax){ * if(listTimePeriod.SelectedIndex==0){ * BenCur.TimePeriod=BenefitTimePeriod.ServiceYear; * } * if(listTimePeriod.SelectedIndex==1){ * BenCur.TimePeriod=BenefitTimePeriod.CalendarYear; * } * } * else{*/ BenCur.TimePeriod = (BenefitTimePeriod)listTimePeriod.SelectedIndex; //} BenCur.Quantity = PIn.Byte(textQuantity.Text); BenCur.QuantityQualifier = (BenefitQuantity)listQuantityQualifier.SelectedIndex; BenCur.CoverageLevel = (BenefitCoverageLevel)listCoverageLevel.SelectedIndex; //if(IsNew){ // BenCur.Insert(); //} //else{ // BenCur.Update(); //} DialogResult = DialogResult.OK; }
private bool TryToSaveData() { if (!butOK.Enabled) //if the OK button is not enabled, user does not have permission. { return(true); } if (textShowInTerminal.errorProvider1.GetError(textShowInTerminal) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return(false); } DateTime dateTimeSheet = DateTime.MinValue; try{ dateTimeSheet = DateTime.Parse(textDateTime.Text); } catch { MsgBox.Show(this, "Please fix data entry errors first."); return(false); } SheetCur.DateTimeSheet = dateTimeSheet; SheetCur.Description = textDescription.Text; SheetCur.InternalNote = textNote.Text; SheetCur.ShowInTerminal = PIn.Byte(textShowInTerminal.Text); FillFieldsFromControls(); //But SheetNums will still be 0 for a new sheet. bool isNew = SheetCur.IsNew; if (isNew) { Sheets.Insert(SheetCur); } else { Sheets.Update(SheetCur); } List <SheetField> drawingList = new List <SheetField>(); foreach (SheetField fld in SheetCur.SheetFields) { if (fld.FieldType == SheetFieldType.SigBox) { continue; //done in a separate step } if (fld.FieldType == SheetFieldType.Image || fld.FieldType == SheetFieldType.Rectangle || fld.FieldType == SheetFieldType.Line) { if (!fld.IsNew) { continue; //it only saves them when the sheet is first created because user can't edit anyway. } } fld.SheetNum = SheetCur.SheetNum; //whether or not isnew if (fld.FieldType == SheetFieldType.Drawing) { fld.IsNew = true; drawingList.Add(fld); } else { if (fld.IsNew) { SheetFields.Insert(fld); } else { SheetFields.Update(fld); } } } if (drawingsAltered) { //drawings get saved as a group rather than with the other fields. SheetFields.SetDrawings(drawingList, SheetCur.SheetNum); } if (isNew) { Sheets.SaveParameters(SheetCur); } //SigBoxes must come after ALL other types in order for the keyData to be in the right order. SheetField field; foreach (Control control in panelMain.Controls) { if (control.GetType() != typeof(OpenDental.UI.SignatureBoxWrapper)) { continue; } if (control.Tag == null) { continue; } field = (SheetField)control.Tag; OpenDental.UI.SignatureBoxWrapper sigBox = (OpenDental.UI.SignatureBoxWrapper)control; if (sigBox.GetSigChanged()) { //refresh the fields so they are in the correct order SheetFields.GetFieldsAndParameters(SheetCur); bool sigIsTopaz = sigBox.GetSigIsTopaz(); string keyData = Sheets.GetSignatureKey(SheetCur); string signature = sigBox.GetSignature(keyData); field.FieldValue = ""; if (signature != "") { if (sigIsTopaz) { field.FieldValue += "1"; } else { field.FieldValue += "0"; } field.FieldValue += signature; } } field.SheetNum = SheetCur.SheetNum; //whether or not isnew if (isNew) //is this really testing the proper object? { SheetFields.Insert(field); } else { SheetFields.Update(field); } } return(true); }