Exemple #1
0
        void checkBeforeCopyFile(string sourceFileName, string destFileName)
        {
            try
            {
                if (File.Exists(destFileName))
                {
                    DialogResult result = MessageBox.Show("Đã tồn tại file: '" + Path.GetFileName(destFileName) + "' trong thiết kế" + Environment.NewLine +
                                                          "Bạn có muốn ghi đè lên file cũ không?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        File.Delete(destFileName);
                        File.Copy(sourceFileName, destFileName);

                        if (pictureBox1.Image != null)
                        {
                            pictureBox1.Image.Dispose();
                        }

                        File.Delete(sourceFileName);
                    }
                    else
                    {
                        TextUtils.RenameFileVB(sourceFileName, Path.GetFileName(destFileName));
                    }
                }
                else
                {
                    File.Copy(sourceFileName, destFileName);
                    if (pictureBox1.Image != null)
                    {
                        pictureBox1.Image.Dispose();
                    }
                    File.Delete(sourceFileName);
                }
            }
            catch (Exception ex)
            {
                TextUtils.ShowError(ex);
            }
        }
        private void btnRename_Click(object sender, EventArgs e)
        {
            try
            {
                TextUtils.RenameFileVB(SelectedFilePath, (txtFileName.Text.ToUpper().Replace(" ", "")) + Path.GetExtension(SelectedFilePath));
                if (Path.GetExtension(SelectedFilePath) == ".jpg")
                {
                    string destFileName = "D:\\Thietke.Ck\\" + ProductCode.Substring(0, 6) + "\\" + ProductCode + ".Ck\\BCCk." + ProductCode + "\\BC-CAD." + ProductCode + "\\"
                                          + (txtFileName.Text.ToUpper().Replace(" ", "")) + Path.GetExtension(SelectedFilePath);

                    string sourceFile = Path.GetDirectoryName(SelectedFilePath) + "\\" + (txtFileName.Text.Replace(" ", "")) + Path.GetExtension(SelectedFilePath);
                    if (File.Exists(destFileName))
                    {
                        DialogResult result = MessageBox.Show("Đã tồn tại file: '" + Path.GetFileName(destFileName) + "' trong thư mục BC-CAD." + ProductCode + Environment.NewLine +
                                                              "Bạn có muốn ghi đè lên file cũ không?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            File.Copy(sourceFile, destFileName, true);
                            File.Delete(sourceFile);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        File.Move(sourceFile, destFileName);
                    }
                }
            }
            catch (Exception ex)
            {
                TextUtils.ShowError(ex);
                return;
            }

            DialogResult = DialogResult.OK;
        }
Exemple #3
0
        void rename(string initPath)
        {
            string folderName = Path.GetFileName(initPath);

            string[] listInitFile = Directory.GetFiles(initPath, "*" + _oldModuleCode + "*", SearchOption.TopDirectoryOnly);
            foreach (string filePath in listInitFile)
            {
                string fileName = Path.GetFileName(filePath);
                if (folderName.StartsWith("DOC.") && Path.GetExtension(filePath) == ".xlsm")
                {
                    Excel.Application objXLApp = default(Excel.Application);
                    Excel.Workbook    objXLWb  = default(Excel.Workbook);
                    Excel.Worksheet   objXLWs  = default(Excel.Worksheet);
                    try
                    {
                        objXLApp = new Excel.Application();
                        objXLApp.Workbooks.Open(filePath);
                        objXLWb = objXLApp.Workbooks[1];
                        objXLWs = (Excel.Worksheet)objXLWb.Worksheets[1];

                        if (fileName.StartsWith("DMVTC."))
                        {
                            objXLWs.Cells[3, 3]  = _newModuleName;
                            objXLWs.Cells[3, 10] = "Mã: " + _newModuleCode;
                            //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper();
                            objXLWs.PageSetup.LeftHeader = _newModuleName;
                        }

                        if (fileName.StartsWith("DTSB."))
                        {
                            objXLWs.Cells[3, 3]  = _newModuleName;
                            objXLWs.Cells[3, 11] = _newModuleCode;
                            //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper();
                            objXLWs.PageSetup.LeftHeader = _newModuleName;
                        }

                        if (fileName.StartsWith("HS."))
                        {
                            objXLWs.Cells[5, 3] = _newModuleName;
                            objXLWs.Cells[6, 3] = _newModuleCode;
                            //objXLWs.Cells[7, 3] = Global.AppUserName.ToUpper();
                            objXLWs.PageSetup.LeftHeader = _newModuleCode + " - " + _newModuleName;
                        }

                        if (fileName.StartsWith("KCS."))
                        {
                            objXLWs.Cells[3, 3] = _newModuleName;
                            objXLWs.Cells[3, 7] = _newModuleCode;
                            //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper();
                            objXLWs.PageSetup.LeftHeader = _newModuleName;
                        }

                        if (fileName.StartsWith("KTVC."))
                        {
                            objXLWs.Cells[4, 3] = _newModuleName;
                            objXLWs.Cells[4, 8] = _newModuleCode;
                            //objXLWs.Cells[5, 3] = Global.AppUserName.ToUpper();
                            objXLWs.PageSetup.LeftHeader = _newModuleName;
                        }

                        if (fileName.StartsWith("XNVT."))
                        {
                            objXLWs.Cells[3, 3]  = _newModuleName;
                            objXLWs.Cells[3, 10] = "Mã: " + _newModuleCode;
                            //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper();
                            objXLWs.PageSetup.LeftHeader = _newModuleName;
                        }
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        objXLApp.ActiveWorkbook.Save();
                        objXLApp.Workbooks.Close();
                        objXLApp.Quit();
                    }
                }

                if (Path.GetExtension(filePath) == ".xlsm")
                {
                    TextUtils.ExcelFindAndReplace(filePath, _oldModuleCode, _newModuleCode);
                }

                TextUtils.RenameFileVB(filePath, Path.GetFileName(filePath).Replace(_oldModuleCode, _newModuleCode));
            }

            string[] listInitFolder = Directory.GetDirectories(initPath, "*" + _oldModuleCode + "*", SearchOption.TopDirectoryOnly);
            foreach (string folderPath in listInitFolder)
            {
                rename(folderPath);
            }

            TextUtils.RenameFolderVB(initPath, Path.GetFileName(initPath).Replace(_oldModuleCode, _newModuleCode));
        }
Exemple #4
0
        private void btnScanAll_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang đổi tên file trong thư mục Scan"))
            {
                for (int i = 0; i < grvScan.RowCount; i++)
                {
                    try
                    {
                        string filePath = grvScan.GetRowCellValue(i, colFilePath).ToString();

                        string thisProductCode = "";

                        if (Path.GetExtension(filePath) == ".jpg")
                        {
                            Image  img     = Image.FromFile(filePath);
                            Bitmap mBitmap = new Bitmap(img);

                            ArrayList barcodes = new ArrayList();
                            BarcodeImaging.FullScanPage(ref barcodes, mBitmap, 100);
                            //string[] barcodes = BarcodeReader.read(mBitmap, BarcodeReader.CODE39);
                            mBitmap.Dispose();
                            string contentBarcode = barcodes.ToArray().Where(o => o.ToString().StartsWith("+")).ToArray()[0].ToString();//nội dung barcode chứa tên biểu mẫu (VD: 2.BM01.A0101)
                            thisProductCode = "TPAD." + contentBarcode.Substring(3);
                            if (!thisProductCode.ToUpper().Contains(_productCode))
                            {
                                continue;
                            }
                            string destFileName = @"D:\Thietke.Ck\TPAD." + _productCode.Substring(5, 1) + "\\" + _productCode + ".Ck\\BCCk."
                                                  + _productCode + "\\BC-CAD." + _productCode + "\\" + thisProductCode + ".jpg";
                            if (File.Exists(destFileName))
                            {
                                DialogResult result = MessageBox.Show("Đã tồn tại file: '" + thisProductCode + ".jpg' trong thiết kế" + Environment.NewLine +
                                                                      "Bạn có muốn ghi đè lên file cũ không?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (result == DialogResult.Yes)
                                {
                                    File.Delete(destFileName);
                                    File.Copy(filePath, destFileName, true);

                                    img.Dispose();
                                    mBitmap.Dispose();
                                    File.Delete(filePath);
                                }
                                else
                                {
                                    TextUtils.RenameFileVB(filePath, thisProductCode + ".jpg");
                                }
                            }
                            else
                            {
                                File.Copy(filePath, destFileName, true);
                                img.Dispose();
                                mBitmap.Dispose();
                                File.Delete(filePath);
                            }
                        }
                        else if (Path.GetExtension(filePath).ToLower() == ".pdf")
                        {
                            System.Collections.ArrayList barcodes = new System.Collections.ArrayList();
                            string outputFilePath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png";
                            pdfConverter().Convert(filePath, outputFilePath);

                            Bitmap mBitmap = new Bitmap(outputFilePath);

                            BarcodeImaging.FullScanPage(ref barcodes, mBitmap, 100);
                            //string[] barcodes = BarcodeReader.read(mBitmap, BarcodeReader.CODE39);

                            mBitmap.Dispose();
                            File.Delete(outputFilePath);

                            string        contentBarcode = barcodes.ToArray().Where(o => o.ToString().StartsWith("2.")).ToArray()[0].ToString();//nội dung barcode chứa tên biểu mẫu (VD: 2.BM01.A0101)
                            string        templateCode   = contentBarcode.Split('.')[1];
                            TemplateModel temModel       = (TemplateModel)TemplateBO.Instance.FindByAttribute("Code", templateCode)[0];

                            int    tempType = temModel.Type;
                            string code     = contentBarcode.Split('.')[2];
                            if (tempType == 1 || tempType == 2) //1:cơ khí,2:điện,3:điện tử
                            {
                                thisProductCode = "TPAD." + code;
                            }
                            else
                            {
                                thisProductCode = "PCB." + code;
                            }

                            if (_productCode != thisProductCode)
                            {
                                continue;
                            }
                            string tempName       = temModel.Name.Replace("code", thisProductCode);
                            string tempFolderPath = temModel.PathFolderC.Replace("code", thisProductCode);

                            if (tempType == 1)
                            {
                                string destFileName = @"D:\Thietke.Ck\TPAD." + code.Substring(0, 1) + "\\" + tempFolderPath + "\\"
                                                      + tempName + Path.GetExtension(filePath);
                                checkBeforeCopyFile(filePath, destFileName);
                            }
                            if (tempType == 2)
                            {
                            }
                            if (tempType == 3)
                            {
                                string destFileName = @"D:\Thietke.Dt\PCB." + code.Substring(0, 1) + "\\" + tempFolderPath + "\\"
                                                      + tempName + ".pdf";
                                checkBeforeCopyFile(filePath, destFileName);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }

                btnRefresh_Click(null, null);
            }
        }