Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang download file CAD tổng..."))
                {
                    foreach (string filePathIAM in ofd.FileNames)
                    {
                        try
                        {
                            IPTDetail.LoadData(filePathIAM);
                            Image img = IPTDetail.Image;
                            //img.Save(@"\\SERVER\data2\Dulieu_TPA\PHANMEM\ModuleImage\" + Module.Code + ".jpg", ImageFormat.Jpeg);
                            //@"\\SERVER\data2\Dulieu_TPA\PHANMEM\ModuleImage\" + Module.Code + ".jpg";
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                //IPTDetail.LoadData(ofd.FileName);
                //Image img = IPTDetail.Image;
                ////img.Save("\\SERVER\\data2\\Thietke\\PHANMEM\\ModuleImage\\" + Path.GetFileNameWithoutExtension(ofd.FileName) + ".jpg", ImageFormat.Jpeg);
                //img.Save("\\SERVER\\data2\\Dulieu_TPA\\PHANMEM\\ModuleImage\\"+ Path.GetFileNameWithoutExtension(ofd.FileName) + ".jpg", ImageFormat.Jpeg);
                ////pictureBox1.Image = IPTDetail.Image;
            }
            MessageBox.Show("Thành công!");
        }
Example #2
0
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "File .iam|*iam|All File|*.*";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang load ảnh..."))
                {
                    IPTDetail.LoadData(ofd.FileName);
                    string imagePath = TextUtils.GetConfigValue("CoCauPath") + "\\" + CoCau.Code.Trim() + ".png";
                    Bitmap bit       = new Bitmap(IPTDetail.Image, IPTDetail.Image.Width / 3, IPTDetail.Image.Height / 3);
                    bit.Save(imagePath, ImageFormat.Png);
                    pictureBox1.ImageLocation = imagePath;
                }
            }
        }
Example #3
0
        string getIamImagePath(string fptPath)
        {
            try
            {
                string localPath = "D:\\CoCau";
                Directory.CreateDirectory(localPath);
                string fileName = Path.GetFileName(fptPath);
                DocUtils.DownloadFile(localPath, fileName, fptPath);

                IPTDetail.LoadData(localPath + "/" + fileName);
                string imagePath = localPath + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".png";
                Bitmap bit       = new Bitmap(IPTDetail.Image, IPTDetail.Image.Width / 3, IPTDetail.Image.Height / 3);
                bit.Save(imagePath, ImageFormat.Png);

                return(imagePath);
            }
            catch
            {
                return("");
            }
        }
Example #4
0
        void createYC(int groupId, string groupCode, string groupName)
        {
            DataTable           dtThongSo = TextUtils.Select("select * from [MaterialParameters] with(nolock) where [MaterialGroupID] = " + groupId);
            string              localPath = "";
            FolderBrowserDialog fbd       = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                localPath = fbd.SelectedPath + "\\TP-TT13-BM11 - Yêu cầu tạo mã vật tư - LSD 01.xlsx";
            }
            else
            {
                return;
            }

            string filePath = Application.StartupPath + "\\Templates\\TP-TT13-BM11 - Yêu cầu tạo mã vật tư - LSD 01.xlsx";

            try
            {
                File.Copy(filePath, localPath, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: File excel đang được mở.");
                return;
            }

            string materialCode = "";
            string materialName = "";
            string hang         = "";

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "File .ipt|*ipt|All File|*.*";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                IPTDetail.LoadData(ofd.FileName);
                materialCode = IPTDetail.Code;
                materialName = IPTDetail.Name;
                hang         = IPTDetail.Hang;
            }

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo biểu mẫu..."))
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                Excel.Application app       = default(Excel.Application);
                Excel.Workbook    workBoook = default(Excel.Workbook);
                Excel.Worksheet   workSheet = default(Excel.Worksheet);
                try
                {
                    app = new Excel.Application();
                    app.Workbooks.Open(localPath);
                    workBoook = app.Workbooks[1];
                    workSheet = (Excel.Worksheet)workBoook.Worksheets[1];

                    workSheet.Cells[12, 4] = "Hà Nội, Ngày " + string.Format("{0:00}", DateTime.Now.Day)
                                             + " tháng " + string.Format("{0:00}", DateTime.Now.Month)
                                             + " năm " + DateTime.Now.Year;

                    workSheet.Cells[5, 2] = groupName;
                    workSheet.Cells[6, 2] = groupCode;

                    int rowCountMo = dtThongSo.Rows.Count;
                    if (rowCountMo > 0)
                    {
                        for (int i = rowCountMo - 1; i >= 0; i--)
                        {
                            ((Excel.Range)workSheet.Rows[11]).Insert();
                            workSheet.Cells[11, 4] = dtThongSo.Rows[i]["Name"].ToString();
                        }
                    }

                    workSheet.Cells[11, 1] = materialName;
                    workSheet.Cells[11, 2] = materialCode;
                    workSheet.Cells[11, 3] = hang;

                    ((Excel.Range)workSheet.Rows[10]).Delete();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (app != null)
                    {
                        app.ActiveWorkbook.Save();
                        app.Workbooks.Close();
                        app.Quit();
                    }
                }
                Process.Start(localPath);
            }
        }
Example #5
0
        private void btnUpIPT_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "File .ipt|*ipt|All File|*.*";
            ofd.Multiselect      = false;
            ofd.InitialDirectory = Settings.Default.TK_IptPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Settings.Default.TK_IptPath = Path.GetDirectoryName(ofd.FileName);
                Settings.Default.Save();

                IPTDetail.LoadData(ofd.FileName);

                #region Check Validate
                if (Material.Code.Replace(")", "#").Replace("/", "#") != Path.GetFileNameWithoutExtension(ofd.FileName).Replace(")", "#").Replace("/", "#"))
                {
                    MessageBox.Show("Tên của file ipt không giống Mã vật tư!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (IPTDetail.Code != txtCode.Text.Trim())
                {
                    MessageBox.Show("Mã vật tư trong IProperties không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (IPTDetail.Hang != cboHang.Text)
                {
                    MessageBox.Show("Hãng trong IProperties không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                #endregion

                DocUtils.InitFTPTK();

                ProcessTransaction pt = new ProcessTransaction();
                pt.OpenConnection();
                pt.BeginTransaction();
                try
                {
                    using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang up file..."))
                    {
                        FileInfo fInfo = new FileInfo(ofd.FileName);

                        #region MaterialFile
                        MaterialFileModel fileModel;
                        bool      isAdd = true;
                        DataTable dt    = TextUtils.Select("select Path, MaterialID, MaterialCode from vMaterialFile with(nolock) where FileType = 0 and MaterialID = "
                                                           + Material.ID + " and MaterialCode = '" + Path.GetFileNameWithoutExtension(ofd.FileName).Replace(")", "/") + "'");

                        if (dt.Rows.Count > 0)
                        {
                            fileModel             = (MaterialFileModel)MaterialFileBO.Instance.FindByAttribute("Name", Path.GetFileName(ofd.FileName))[0];
                            isAdd                 = false;
                            fileModel.UpdatedDate = TextUtils.GetSystemDate();
                            fileModel.UpdatedBy   = Global.AppUserName;
                        }
                        else
                        {
                            fileModel             = new MaterialFileModel();
                            fileModel.CreatedDate = TextUtils.GetSystemDate();
                            fileModel.CreatedBy   = Global.AppUserName;
                            fileModel.UpdatedDate = Material.CreatedDate;
                            fileModel.UpdatedBy   = Global.AppUserName;
                        }

                        fileModel.Extension    = Path.GetExtension(ofd.FileName);
                        fileModel.Datemodified = fInfo.LastWriteTime;
                        fileModel.Length       = fInfo.Length;
                        fileModel.Name         = Path.GetFileName(fInfo.FullName);
                        fileModel.Path         = "Materials/" + Path.GetFileName(fInfo.FullName);
                        fileModel.IsDeleted    = false;
                        fileModel.FileType     = 0;//0 là file 3D cơ khí, 1 là datasheet
                        #endregion

                        if (isAdd)
                        {
                            fileModel.ID = (int)pt.Insert(fileModel);

                            #region Insert MaterialFileLink
                            //Thêm link giữa file với vật tư
                            MaterialFileLinkModel fileLinkModel = new MaterialFileLinkModel();
                            fileLinkModel.MaterialFileID = fileModel.ID;
                            fileLinkModel.MaterialID     = Material.ID;
                            pt.Insert(fileLinkModel);
                            #endregion
                        }
                        else
                        {
                            pt.Update(fileModel);

                            #region Update material if value different
                            //if (Material.VL != IPTDetail.VL)
                            //{
                            //    frmCompareIPT frm = new frmCompareIPT();
                            //    frm.OldValue = Material.VL;
                            //    frm.IPTValue = IPTDetail.VL;
                            //    if (frm.ShowDialog() == DialogResult.OK)
                            //    {
                            //        string value = frm.RightValue;
                            //        Material.VL = value;
                            //        pt.Update(Material);

                            //        IPTDetail.GetIproperties(ofd.FileName);
                            //    }
                            //}
                            #endregion
                        }

                        #region write Title into ipt file
                        try
                        {
                            IPTDetail.WriteName(ofd.FileName, Material.Name);
                        }
                        catch (Exception)
                        {
                        }
                        #endregion

                        #region Update Material
                        //Update dữ liệu trong iproperties vào trong vật tư
                        Material.Note       = IPTDetail.Note;
                        Material.Unit       = IPTDetail.Unit;
                        Material.VL         = IPTDetail.VL;
                        Material.MaVatLieu  = IPTDetail.MaVatLieu;
                        Material.Properties = IPTDetail.Properties;
                        Material.Author     = IPTDetail.Author;

                        pbAnh.InitialImage = null;
                        pbAnh.Image        = null;

                        ConfigSystemModel cf        = (ConfigSystemModel)ConfigSystemBO.Instance.FindByAttribute("KeyName", "MaterialImagePath")[0];//
                        string            imagePath = cf.KeyValue + "\\" + Material.Code.Replace("/", ")") + ".png";
                        Bitmap            bit       = new Bitmap(IPTDetail.Image, IPTDetail.Image.Width / 3, IPTDetail.Image.Height / 3);
                        bit.Save(imagePath, ImageFormat.Png);

                        Material.ImagePath = imagePath;
                        Material.File3D    = 1;
                        pt.Update(Material);
                        #endregion

                        DocUtils.UploadFile(ofd.FileName, "Materials");

                        pt.CommitTransaction();

                        loadIpt();

                        #region Load textbox
                        txtGhiChu.Text     = Material.Note;
                        txtDonVi.Text      = Material.Unit;
                        txtVatLieu.Text    = Material.VL;
                        txtVatTuNguon.Text = Material.MaVatLieu;
                        txtTTGiaCong.Text  = Material.Properties;
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Up file không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                finally
                {
                    pt.CloseConnection();
                }
            }
        }