예제 #1
0
        /// <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();
        }
        /// <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();
        }
 void OpenDrawingExecute()
 {
     try
     {
         Drawing d = SelectedDrawing;
         DBCommon.OpenAutoCadDrawing(d.FileName);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 partial void DeleteDrawing(Drawing instance);
 partial void UpdateDrawing(Drawing instance);
 partial void InsertDrawing(Drawing instance);
예제 #7
0
 /// <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, bool enableEditByDefault) : this(drawing, refresh)
 {
     _enableEditByDefualt = enableEditByDefault;
 }
 /// <summary>
 /// Create a drawing template from given drawing with the given path/title
 /// </summary>
 /// <param name="title"></param>
 /// <param name="drawing"></param>
 public TemplateDrawingModel(string title, Drawing drawing)
 {
     if (drawing == null)
     {
         throw new ArgumentNullException("d");
     }
     _path = title;
     //clone the drawing so subsequent changes effect only one copy
     _originalDrawing = drawing.Clone() as Drawing;
     //same here, clone the working copy.  Shallow copy ok as all members are value or immutable reference types.
     _drawing = _originalDrawing.Clone() as Drawing;
 }
 /// <summary>
 /// Create a new drawing template from the persisted/serialized drawing
 /// </summary>
 /// <param name="path"></param>
 public TemplateDrawingModel(string path) 
 {
     StreamReader sr = new StreamReader(path);
     XmlSerializer xml = new XmlSerializer(typeof(Drawing));
     Drawing d = xml.Deserialize(sr) as Drawing;
     if (d != null)
     {
         _path = path;
         _originalDrawing = d;
         _drawing = _originalDrawing.Clone() as Drawing;
     }
 }
 /// <summary>
 /// Save the template.
 /// If it doesnt already exist, then SaveFileDialog will be displayed unless the noPrompt parameter is set.
 /// </summary>
 public void SaveTemplate(bool noPrompt = false)
 {
     if (!File.Exists(_path) && !noPrompt)
     {
         SaveFileDialog d = new SaveFileDialog();
         if (d.ShowDialog() == true)
         {
             Path = d.FileName;
         }
         else
         {
             return;
         }
     }
     StreamWriter sw = new StreamWriter(Path);
     XmlSerializer xml = new XmlSerializer(typeof(Drawing));
     xml.Serialize(sw, Drawing);
     OriginalDrawing = Drawing.Clone() as Drawing;
     sw.Dispose();
 }
 /// <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, bool enableEditByDefault) : this(drawing, refresh)
 {
     _enableEditByDefualt = enableEditByDefault;
 }
        private bool AecomBlockToDatabase(BlockReference block, Transaction tr)
        {
            try
            {
                Dictionary<string, AttributeReference> attribs = GetBlockAttributes(block, tr);
                string sheet = "";//aecom blocks have no sheet attribute so lets keep track of it separate.
                string number = "";

                PromptStringOptions pso = new PromptStringOptions("Drawing Number:");
                pso.DefaultValue = GetAttribute(attribs, "Number");
                PromptResult pr1 = _ed.GetString(pso);
               
                if (pr1.Status == PromptStatus.Cancel)
                    return false;
                if (string.IsNullOrWhiteSpace(pr1.StringResult))
                    return false;
                number = pr1.StringResult;

                pso = new PromptStringOptions("Sheet Number:");
                pso.DefaultValue = "1";
                pr1 = _ed.GetString(pso);
                if (pr1.Status == PromptStatus.Cancel)
                    return false;
                if (string.IsNullOrWhiteSpace(pr1.StringResult))
                    return false;
                sheet = pr1.StringResult;


                DrawingsDataContext dc = DBCommon.NewDC;
                Drawing drawing = DrawingHelper.GetDrawing(dc, number, sheet);

                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.Number = number; //override the block with what we know from earlier
                drawing.Sheet = sheet;
                drawing.DrawnDate = drawing.ApprovedDate;
                drawing.SheetSize = "A3";
                drawing.Consultant = "AECOM / MAUNSEL";
                drawing.Category = DrawingCategory.ZoneSubstation;
                _ed.WriteMessage("INFO:  Drawing Category set to ZONE SUBSTATION.\n");


                //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;
                }
                //If we're putting this in via the CAD, then it must be electronic
                drawing.Electronic = true;

                dc.SubmitChanges();

                if (drawing.Category == DrawingCategory.Undefined)
                {
                    System.Windows.MessageBox.Show("Your drawing has an invalid category.  Please fix it and try again.", "OI.  CHECK YOUR SPELLING DUMMY");
                    _ed.WriteMessage("WARNING:  Drawing Category is undefined!\n");
                }
                if (drawing.Status == DrawingStatus.Undefined)
                {
                    System.Windows.MessageBox.Show("Your drawing has an invalid status.  Please fix it and try again.", "OI. CHECK YOUR SPELLING DUMMMY");
                    _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;
            }
        }
        private bool BlockToDatabase(BlockReference block, Transaction tr)
        {
            try
            {
                Dictionary<string, AttributeReference> attribs = GetBlockAttributes(block, tr);

                while(String.IsNullOrEmpty(GetAttribute(attribs, "Number")))
                {
                    PromptResult pr1 = _ed.GetString("Drawing Number:");
                    if (pr1.Status == PromptStatus.Cancel)
                        return false;
                    SetAttribute(attribs, "Number", pr1.StringResult);
                }
                while (String.IsNullOrEmpty(GetAttribute(attribs, "Sheet")))
                {
                    PromptResult pr1 = _ed.GetString("Sheet Number:");
                    if (pr1.Status == PromptStatus.Cancel)
                        return false;
                    SetAttribute(attribs, "Sheet", pr1.StringResult);
                }
                
                DrawingsDataContext dc = DBCommon.NewDC;
                Drawing drawing = DrawingHelper.GetDrawing(dc, GetAttribute(attribs, "Number"), GetAttribute(attribs, "Sheet"));

                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;
                }
                //If we're putting this in via the CAD, then it must be electronic
                drawing.Electronic = true;

                dc.SubmitChanges();

                if (drawing.Category == DrawingCategory.Undefined)
                {
                    System.Windows.MessageBox.Show("Your drawing has an invalid category.  Please fix it and try again.", "OI.  CHECK YOUR SPELLING DUMMY");
                    _ed.WriteMessage("WARNING:  Drawing Category is undefined!\n");
                }
                if (drawing.Status == DrawingStatus.Undefined)
                {
                    System.Windows.MessageBox.Show("Your drawing has an invalid status.  Please fix it and try again.", "OI. CHECK YOUR SPELLING DUMMMY");
                    _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;
            }
        }