예제 #1
0
        /// <summary>
        /// 获取所选文件夹的文件
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public static void GetAllFiles(DirectoryInfo dir)
        {
            List <HistoryDto> listHis = new List <HistoryDto>();

            FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
            foreach (FileSystemInfo info in fileinfo)
            {
                if (info is DirectoryInfo)
                {
                    GetAllFiles((DirectoryInfo)info);
                }
                else
                {
                    var extension = info.Extension;
                    if (extension.Equals(".dwg") || extension.Equals(".dwt") || extension.Equals(".dws") || extension.Equals(".dxf"))
                    {
                        if (Util.GetDrwingsDto(info.Name) == null)
                        {
                            HistoryDto dto = new HistoryDto();
                            dto.Id         = Guid.NewGuid().ToString();
                            dto.FileName   = info.Name;
                            dto.FilePath   = info.FullName.Replace("\\", "\\\\");
                            dto.FileStatus = "未处理";
                            listHis.Add(dto);
                        }
                    }
                }
            }
            InsertHistory(listHis);
            listHis.Clear();
        }
예제 #2
0
        public static HistoryDto GetDrwingsDto(string path)
        {
            //MysqlOperate operate = new MysqlOperate();
            HistoryDto dto = operate.GetDrwingsDto(path);

            return(dto);
        }
예제 #3
0
 /// <summary>
 /// 获取所选文件夹的文件
 /// </summary>
 /// <param name="dir"></param>
 /// <returns></returns>
 public static void GetAllFiles(DirectoryInfo dir)
 {
     List<HistoryDto> listHis = new List<HistoryDto>();
     FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
     foreach (FileSystemInfo info in fileinfo)
     {
         if (info is DirectoryInfo)
         {
             GetAllFiles((DirectoryInfo)info);
         }
         else
         {
             var extension = info.Extension;
             if (extension.Equals(".dwg") || extension.Equals(".dwt") || extension.Equals(".dws") || extension.Equals(".dxf"))
             {
                 if (Util.GetDrwingsDto(info.Name) == null)
                 {
                     HistoryDto dto = new HistoryDto();
                     dto.Id = Guid.NewGuid().ToString();
                     dto.FileName = info.Name;
                     dto.FilePath = info.FullName.Replace("\\", "\\\\");
                     dto.FileStatus = "未处理";
                     listHis.Add(dto);
                 }
             }
         }
     }
     InsertHistory(listHis);
     listHis.Clear();
 }
예제 #4
0
 public HistoryDto GetDrwingsDto(string filename)
 {
     HistoryDto dto = new HistoryDto();
     var strSql = "SELECT * FROM history WHERE filename='" + filename + "'";
     DataSet ds = MysqlDBUtil.Query(strSql);
     for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
     {
         dto.Id = ds.Tables[0].Rows[i]["id"].ToString();
         dto.FileName = ds.Tables[0].Rows[i]["filename"].ToString();
         dto.FilePath = ds.Tables[0].Rows[i]["filepath"].ToString();
         dto.FileStatus = ds.Tables[0].Rows[i]["id"].ToString();
         return dto;
     }
     return null;
 }
예제 #5
0
        public HistoryDto GetDrwingsDto(string filename)
        {
            HistoryDto dto    = new HistoryDto();
            var        strSql = "SELECT * FROM history WHERE filename='" + filename + "'";
            DataSet    ds     = MysqlDBUtil.Query(strSql);

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dto.Id         = ds.Tables[0].Rows[i]["id"].ToString();
                dto.FileName   = ds.Tables[0].Rows[i]["filename"].ToString();
                dto.FilePath   = ds.Tables[0].Rows[i]["filepath"].ToString();
                dto.FileStatus = ds.Tables[0].Rows[i]["id"].ToString();
                return(dto);
            }
            return(null);
        }
예제 #6
0
        public void InsertHistory(HistoryDto dto)
        {
            var strSql = "INSERT INTO history(Id,FileName,FileStatus,FilePath) VALUES('" + dto.Id + "','" + dto.FileName + "','" + dto.FileStatus + "','" + dto.FilePath + "')";

            MysqlDBUtil.ExecuteSql(strSql);
        }
예제 #7
0
        public void UpdateHistory(HistoryDto dto)
        {
            var strSql = "UPDATE history SET FileName = '" + dto.FileName + "',FileStatus='" + dto.FileStatus + "',FilePath='" + dto.FilePath + "' WHERE id='" + dto.Id + "'";

            MysqlDBUtil.ExecuteSql(strSql);
        }
예제 #8
0
 public static void UpdateHistory(HistoryDto dto)
 {
     //MysqlOperate operate = new MysqlOperate();
     operate.UpdateHistory(dto);
 }
예제 #9
0
 public static void UpdateHistory(HistoryDto dto)
 {
     //MysqlOperate operate = new MysqlOperate();
     operate.UpdateHistory(dto);
 }
예제 #10
0
        private void UpdateCAD()
        {
            var showInfo = "";
            var fileStaus = "";
            if (string.IsNullOrEmpty(txtSavePath.Text))
            {
                MessageBox.Show("请选择文件保存位置!", "提示信息"); return;
            }
            var FilePath = "";
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int k = 0; k < lvwList.Items.Count; k++)
            {
                lblTips.Text = "当前共有: " + lvwList.Items.Count + " 张图纸需要处理,现在正在处理第 " + (k + 1) + " 张";
                FilePath = lvwList.Items[k].ToString();
                AcadDoc = acAppComObj.Documents.Open(FilePath, null, null);
                acAppComObj.Application.Visible = false;
                AcadBlocks blocks = AcadDoc.Blocks;
                HistoryDto dto = new HistoryDto();
                CodeDto codeDto = new CodeDto();
                dto.Id = Guid.NewGuid().ToString();
                dto.FileName = AcadDoc.Name;
                dto.FilePath = FilePath;
                try
                {
                    foreach (AcadBlock block in blocks)
                    {
                        foreach (AcadEntity entity in block)
                        {
                            list.Add(entity.ObjectName);

                            ////1.替换基本属性
                            //Util.ReplaceProperty(entity);
                            ////2.替换装配图的明细表编号
                            //Util.ReplaceDrawingCode(entity, acAppComObj);
                            //entity.Update();
                        }
                    }
                    fileStaus = "图纸处理完成";
                    dto.FileStatus = fileStaus;
                    //3.处理情况保存
                    //InsertHistory(dto);
                    codeDto.Id = Guid.NewGuid().ToString();
                    codeDto.OldCode = Util.oldCode;
                    codeDto.NewCode = Util.newCode;
                    //InsertCode(codeDto);
                }
                catch (Exception ex)
                {
                    fileStaus = "图纸处理异常,异常原因:" + ex.Message;
                    dto.FileStatus = fileStaus;
                    //3.处理情况保存
                    //InsertHistory(dto);
                    continue;
                }
                dto.FileStatus = fileStaus;

                //判断是否需要保存,如需要则另存为
                if (acAppComObj.ActiveDocument.Saved == false)
                {
                    acAppComObj.ActiveDocument.SaveAs(txtSavePath.Text + "\\" + Util.newCode, AcSaveAsType.ac2013_dwg, null);
                    GC.Collect();
                }
            }
            stopwatch.Stop(); //  停止监视
            TimeSpan timespan = stopwatch.Elapsed; //  获取当前实例测量得出的总时间
            double hours = timespan.TotalHours; // 总小时
            double minutes = timespan.TotalMinutes;  // 总分钟
            double seconds = timespan.TotalSeconds;  //  总秒数
            double milliseconds = timespan.TotalMilliseconds;  //  总毫秒数
            lvwList.DataSource = list;
            MessageBox.Show(fileStaus);
            //MessageBox.Show("图纸修改完成,修改所花时间为:" + seconds.ToString());
            MessageBox.Show(showInfo);
        }
예제 #11
0
 void InsertHistory(HistoryDto dto)
 {
     MysqlOperate operate = new MysqlOperate();
     operate.InsertHistory(dto);
 }
예제 #12
0
 public void UpdateHistory(HistoryDto dto)
 {
     var strSql = "UPDATE history SET FileName = '" + dto.FileName + "',FileStatus='" + dto.FileStatus + "',FilePath='" + dto.FilePath + "' WHERE id='" + dto.Id + "'";
     MysqlDBUtil.ExecuteSql(strSql);
 }
예제 #13
0
 public void InsertHistory(HistoryDto dto)
 {
     var strSql = "INSERT INTO history(Id,FileName,FileStatus,FilePath) VALUES('" + dto.Id + "','" + dto.FileName + "','" + dto.FileStatus + "','" + dto.FilePath + "')";
     MysqlDBUtil.ExecuteSql(strSql);
 }
예제 #14
0
        private void UpdateCAD()
        {
            var showInfo  = "";
            var fileStaus = "";

            if (string.IsNullOrEmpty(txtSavePath.Text))
            {
                MessageBox.Show("请选择文件保存位置!", "提示信息"); return;
            }
            var       FilePath  = "";
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int k = 0; k < lvwList.Items.Count; k++)
            {
                lblTips.Text = "当前共有: " + lvwList.Items.Count + " 张图纸需要处理,现在正在处理第 " + (k + 1) + " 张";
                FilePath     = lvwList.Items[k].ToString();
                AcadDoc      = acAppComObj.Documents.Open(FilePath, null, null);
                acAppComObj.Application.Visible = false;
                AcadBlocks blocks  = AcadDoc.Blocks;
                HistoryDto dto     = new HistoryDto();
                CodeDto    codeDto = new CodeDto();
                dto.Id       = Guid.NewGuid().ToString();
                dto.FileName = AcadDoc.Name;
                dto.FilePath = FilePath;
                try
                {
                    foreach (AcadBlock block in blocks)
                    {
                        foreach (AcadEntity entity in block)
                        {
                            list.Add(entity.ObjectName);

                            ////1.替换基本属性
                            //Util.ReplaceProperty(entity);
                            ////2.替换装配图的明细表编号
                            //Util.ReplaceDrawingCode(entity, acAppComObj);
                            //entity.Update();
                        }
                    }
                    fileStaus      = "图纸处理完成";
                    dto.FileStatus = fileStaus;
                    //3.处理情况保存
                    //InsertHistory(dto);
                    codeDto.Id      = Guid.NewGuid().ToString();
                    codeDto.OldCode = Util.oldCode;
                    codeDto.NewCode = Util.newCode;
                    //InsertCode(codeDto);
                }
                catch (Exception ex)
                {
                    fileStaus      = "图纸处理异常,异常原因:" + ex.Message;
                    dto.FileStatus = fileStaus;
                    //3.处理情况保存
                    //InsertHistory(dto);
                    continue;
                }
                dto.FileStatus = fileStaus;

                //判断是否需要保存,如需要则另存为
                if (acAppComObj.ActiveDocument.Saved == false)
                {
                    acAppComObj.ActiveDocument.SaveAs(txtSavePath.Text + "\\" + Util.newCode, AcSaveAsType.ac2013_dwg, null);
                    GC.Collect();
                }
            }
            stopwatch.Stop();                                   //  停止监视
            TimeSpan timespan     = stopwatch.Elapsed;          //  获取当前实例测量得出的总时间
            double   hours        = timespan.TotalHours;        // 总小时
            double   minutes      = timespan.TotalMinutes;      // 总分钟
            double   seconds      = timespan.TotalSeconds;      //  总秒数
            double   milliseconds = timespan.TotalMilliseconds; //  总毫秒数

            lvwList.DataSource = list;
            MessageBox.Show(fileStaus);
            //MessageBox.Show("图纸修改完成,修改所花时间为:" + seconds.ToString());
            MessageBox.Show(showInfo);
        }
예제 #15
0
        //private void UpdateCad_DoWork(object sender, DoWorkEventArgs e)
        //{
        //    UpdateCadDoWork((BackgroundWorker)sender, e);
        //    //Test((BackgroundWorker)sender, e);
        //}

        //private void UpdateCadDoWork(BackgroundWorker worker, DoWorkEventArgs e)
        //{
        //    UpdateCAD();
        //}
        #endregion

        void InsertHistory(HistoryDto dto)
        {
            MysqlOperate operate = new MysqlOperate();

            operate.InsertHistory(dto);
        }