예제 #1
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();
                }
            }
        }
예제 #2
0
        void save(bool close)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();
            try
            {
                if (!ValidateForm())
                {
                    return;
                }
                string oldName = Material.Name;
                Material.Name            = txtName.Text.Trim().ToUpper();
                Material.Code            = txtCode.Text.Trim();
                Material.CustomerID      = TextUtils.ToInt(cboHang.EditValue);
                Material.MaterialGroupID = TextUtils.ToInt(leParentCat.EditValue);

                Material.Unit               = txtDonVi.Text;
                Material.Note               = txtGhiChu.Text;
                Material.Price              = TextUtils.ToDecimal(txtPrice.Text);
                Material.PriceTemp          = TextUtils.ToDecimal(txtPriceTemp.Text);
                Material.DeliveryPeriod     = TextUtils.ToDecimal(txtTGiaoHang.Text);
                Material.DeliveryPeriodTemp = txtTGiaoHangTemp.Text.Trim();
                Material.ThoiGianGHCuoi     = txtTGiaoHangCuoi.Text;
                Material.Properties         = txtTTGiaCong.Text;
                Material.VL         = txtVatLieu.Text;
                Material.MaVatLieu  = txtVatTuNguon.Text;
                Material.Weight     = TextUtils.ToDecimal(txtWeight.Text);
                Material.StopStatus = chkTamDung.Checked;
                Material.IsUse      = chkThuongSuDung.Checked;

                if (Material.ID <= 0)
                {
                    Material.CreatedDate = TextUtils.GetSystemDate();
                    Material.CreatedBy   = Global.AppUserName;
                    Material.UpdatedDate = Material.CreatedDate;
                    Material.UpdatedBy   = Global.AppUserName;
                    Material.ID          = (int)pt.Insert(Material);
                }
                else
                {
                    Material.UpdatedDate = TextUtils.GetSystemDate();
                    Material.UpdatedBy   = Global.AppUserName;
                    pt.Update(Material);

                    //update tên cho file ipt
                    if (oldName != Material.Name && Material.File3D > 0)
                    {
                        using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang update tên cho file 3D..."))
                        {
                            string filePathIpt   = "Materials/" + Material.Code + ".ipt";
                            string localPath     = Path.GetTempPath();
                            string fileName      = Material.Code + ".ipt";
                            string filePathLocal = localPath + "/" + fileName;

                            DocUtils.DownloadFile(localPath, fileName, filePathIpt);

                            IPTDetail.WriteName(filePathLocal, Material.Name);

                            DocUtils.UploadFile(filePathLocal, "Materials");
                        }
                    }
                }

                //Lưu trữ thông số
                for (int i = 0; i < grvData.RowCount; i++)
                {
                    int       paraID     = TextUtils.ToInt(grvData.GetRowCellValue(i, colID));
                    int       materialID = TextUtils.ToInt(grvData.GetRowCellValue(i, colMaterialID));
                    DataTable dt         = TextUtils.Select("MaterialParameterLink", new Expression("MaterialID", materialID)
                                                            .And(new Expression("MaterialParameterID", paraID)));
                    if (dt.Rows.Count > 0)
                    {
                        continue;
                    }
                    MaterialParameterLinkModel model = new MaterialParameterLinkModel();
                    model.MaterialID          = Material.ID;
                    model.MaterialParameterID = paraID;
                    pt.Insert(model);
                }

                pt.CommitTransaction();
                _isSaved = true;
                loadGridPara();
                if (close)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lưu trữ không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }