internal void InsertSheets(int CopyFrom, int InsertBefore, int SheetCount, TWorkbook SourceWorkbook) { if (SourceWorkbook == null) { SourceWorkbook = this; } if (CopyFrom >= SourceWorkbook.Sheets.Count) { XlsMessages.ThrowException(XlsErr.ErrInvalidSheetNo, CopyFrom, -1, SourceWorkbook.Sheets.Count - 1); } if (InsertBefore > Sheets.Count) { XlsMessages.ThrowException(XlsErr.ErrInvalidSheetNo, InsertBefore, 0, Sheets.Count); } TSheet aSheet = null; int OptionFlags = 0; if (CopyFrom >= 0) { aSheet = SourceWorkbook.Sheets[CopyFrom]; OptionFlags = SourceWorkbook.Globals.SheetOptionFlags(CopyFrom); } int NewCopyFrom = CopyFrom; if (SourceWorkbook == this && CopyFrom >= InsertBefore) { NewCopyFrom += SheetCount; } Globals.InsertSheets(CopyFrom, InsertBefore, OptionFlags, XlsMessages.GetString(XlsErr.BaseSheetName), SheetCount, SourceWorkbook.Sheets); TSheetInfo SheetInfo = new TSheetInfo(-1, -1, -1, SourceWorkbook.Globals, Globals, aSheet, null, false); for (int i = 0; i < SheetCount; i++) { SheetInfo.InsSheet = InsertBefore + i; SheetInfo.SourceFormulaSheet = NewCopyFrom; SheetInfo.DestFormulaSheet = InsertBefore; SheetInfo.DestSheet = null; //keep it null, since the reference does not exist yet. if (aSheet == null) { Sheets.Insert(InsertBefore, TWorkSheet.CreateFromData(Globals, Globals.Workbook.XlsBiffVersion, Globals.Workbook.ExcelFileFormat)); } else { SheetInfo.DestFormulaSheet = InsertBefore + i; Globals.Names.InsertSheets(NewCopyFrom, InsertBefore + i, 1, SheetInfo, SourceWorkbook == this); //names must be inserted before the sheet is cloned, so formulas can refer to them. Sheets.Insert(InsertBefore + i, TSheet.Clone(aSheet, SheetInfo)); SheetInfo.DestSheet = Sheets[InsertBefore + i]; Sheets[InsertBefore + i].ArrangeCopySheet(SheetInfo); } } }
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); }