/// <summary> /// Gets the next free drawing number /// </summary> /// <returns></returns> public static string GetNextDrawingNumber() { int nextNum = 0; DrawingsDataContext dc = NewDC; //couldnt really work out how to do this with linq, this is nicer anyways var dwgs = dc.ExecuteQuery <Drawing>("select top 1 * from Drawings where (CONSULTANT='' OR CONSULTANT IS NULL) AND ISNUMERIC(NUMBER) != 0 order by CAST(NUMBER AS FLOAT) desc"); try { Drawing d2 = dwgs.First(); //our number might be a decimal nextNum = (int)Math.Floor(double.Parse(d2.Number, CultureInfo.InvariantCulture)) + 1; } catch { nextNum++; } if (nextNum < 4000) { nextNum = 4000; //start series at 4000 } return(nextNum.ToString(CultureInfo.InvariantCulture)); }
public static void DeleteDrawing(int id) { DrawingsDataContext dc = NewDC; Drawing drawing = (from d in dc.Drawings where d.Id == id select d).Single(); dc.Drawings.DeleteOnSubmit(drawing); dc.SubmitChanges(); }
/// <summary> /// /// </summary> /// <param name="drawing">The drawing to edit</param> /// <param name="refresh">Some action to perform if the drawing is changed</param> /// <param name="dc"></param> public ViewDrawingWindow(MPDrawing drawing, Action refresh) { InitializeComponent(); _refresh = refresh; _dc = DBCommon.NewDC; _d = (from dwg in _dc.Drawings where dwg.Id == drawing.Id select dwg).First(); }
public static Drawing GetDrawing(DrawingsDataContext dc, string drawingNumber, string sheetNumber) { IQueryable<Drawing> drawings = (from d in dc.Drawings where d.Number == drawingNumber && d.Sheet == sheetNumber select d); return !drawings.Any() ? null : drawings.First(); }
private static Drawing GetDrawingFromBlock(DrawingsDataContext dc, BlockReference blkRef, Transaction tr) { Dictionary<string, AttributeReference> attribs = GetBlockAttributes(blkRef, tr); return dc.Drawings.FirstOrDefault( d => d.Number == GetAttribute(attribs, "Number") && d.Sheet == GetAttribute(attribs, "Sheet")); }