private void Button_Click(object sender, RoutedEventArgs e) { btnSave.Focus();//prop grid wont save unless it loses focus (which it wont if we press enter instead of click the button) if (propGrid.IsReadOnly) { propGrid.IsReadOnly = false; btnSave.Content = "Save and Close"; lblEditMessage.Visibility = System.Windows.Visibility.Visible; } else { if (DBCommon.DrawingComboExists(_d.Number, _d.Sheet, _d.Id)) { MessageBox.Show("A drawing with the specified number and sheet number already exists."); } else { try { _dc.SubmitChanges(); } catch (Exception ex) { MessageBox.Show("An error has occured while trying to commit changes to the database. A data concurrency exception may have occured, please refresh the data by re-searching." + Environment.NewLine + Environment.NewLine + ex.Message); } this.Close(); } } }
/// <summary> /// Add the working copy drawing to the database /// </summary> public void AddDrawingToDatabase() { DrawingsDataContext dc = DBCommon.NewDC; dc.Drawings.InsertOnSubmit(Drawing); dc.SubmitChanges(); //clone the working copy, so we dont change an existing drawing Drawing = Drawing.Clone() as Drawing; }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (DBCommon.DrawingComboExists(_d.Number, _d.Sheet)) { MessageBox.Show( "A drawing with the specified number and sheet number already exists, or the Drawing Number or Sheet Number was null. This is not acceptable."); } else { DrawingsDataContext dc = DBCommon.NewDC; dc.Drawings.InsertOnSubmit(_d); dc.SubmitChanges(); Close(); } }
private void btnDeleteSelected_Click(object sender, RoutedEventArgs e) { MessageBoxResult res = MessageBox.Show( "Deleting a record cannot be undone. Are you sure you want to delete " + listBox1.SelectedItems.Count + " records?", "Really?", MessageBoxButton.YesNo); if (res != MessageBoxResult.Yes) { return; } foreach (MPDrawing d in listBox1.SelectedItems) { _dc.Drawings.DeleteOnSubmit(d); } _dc.SubmitChanges(); }
public static void CreateAndEditDrawing() { DrawingCommands dc = new DrawingCommands(); //create the drawings Drawing d = dc.CreateDefaultDrawingWithFileName(); if (d == null) { return; } DrawingsDataContext ddc = DBCommon.NewDC; ddc.Drawings.InsertOnSubmit(d); //chuck it in the database ddc.SubmitChanges(); //bring up the window to edit changes ViewDrawingWindow atv = new ViewDrawingWindow(d, null, true); atv.ShowDialog(); }
private void btnUpdateDB_Click(object sender, RoutedEventArgs e) { try { DrawingsDataContext dc = DBCommon.NewDC; IEnumerable <DrawingInfo> selectedDrawings = (from d in _drawings where d.Include select d); foreach (DrawingInfo di in selectedDrawings) { IQueryable <Drawing> dwgs = (from MPDrawing d in dc.Drawings where d.Number.ToLower() == di.Name.ToLower() select d); foreach (MPDrawing dwg in dwgs) { dwg.FileName = di.Path; } } dc.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private bool BlockToDatabase(BlockReference block, Transaction tr) { try { Dictionary <string, AttributeReference> attribs = GetBlockAttributes(block, tr); if (String.IsNullOrEmpty(attribs["DRAWING-NUMBER"].TextString)) { PromptResult pr1 = _ed.GetString("Drawing Number:"); attribs["DRAWING-NUMBER"].TextString = pr1.StringResult; } if (String.IsNullOrEmpty(attribs["SHEET"].TextString)) { PromptResult pr1 = _ed.GetString("Sheet Number:"); attribs["SHEET"].TextString = pr1.StringResult; } if (String.IsNullOrEmpty(attribs["DRAWING-NUMBER"].TextString) || String.IsNullOrEmpty(attribs["SHEET"].TextString)) { _ed.WriteMessage("No drawing/sheet number forthcoming, returning.\n"); return(false); } DrawingsDataContext dc = DBCommon.NewDC; Drawing drawing = GetDrawing(dc, attribs["DRAWING-NUMBER"].TextString, attribs["SHEET"].TextString); if (drawing == null) { drawing = new Drawing(); dc.Drawings.InsertOnSubmit(drawing); } foreach (var kvp in attribs) { if (DrawingHelper.AttributeExists(kvp.Key)) //only save the desired attributes { drawing.SetAttribute(kvp.Key, kvp.Value.TextString); } } drawing.SheetSize = GetSheetSizeFromBlock(block, tr); //TODO: check this if (_db.Filename.EndsWith("sv$", StringComparison.OrdinalIgnoreCase)) { _ed.WriteMessage("File has not been saved since autosave, filename not put into the database.\n"); } else { drawing.FileName = _db.Filename; //drawing.Filename = _db.OriginalFileName; } //If we're putting this in via the CAD, then it must be electronic drawing.Electronic = true; dc.SubmitChanges(); if (drawing.Category == DrawingCategory.Undefined) { _ed.WriteMessage("WARNING: Drawing Category is undefined!\n"); } if (drawing.Status == DrawingStatus.Undefined) { _ed.WriteMessage("WARNING: Drawing Status is undefined!\n"); } _ed.WriteMessage("Data successfully written to the database from block " + block.Name + "\n"); return(true); } catch (Exception ex) { _ed.WriteMessage(ex.Message); return(false); } }