示例#1
0
 private void btnNoApprove_Click(object sender, EventArgs e)
 {
     foreach (int item in grvGrid.GetSelectedRows())
     {
         int mID = TextUtils.ToInt(grvGrid.GetRowCellValue(item, colMaterialFileID));
         MaterialFileModel model = (MaterialFileModel)MaterialFileBO.Instance.FindByPK(mID);
         //model.CauseDelete = "";
         model.IsDeleted = false;
         MaterialFileBO.Instance.Update(model);
     }
 }
示例#2
0
        private void btnUpDatasheet_Click(object sender, EventArgs e)
        {
            int    cusID = 0;
            string hang  = "";

            if (CustomerID > 0)
            {
                cusID = CustomerID;
                hang  = ((CustomerModel)CustomerBO.Instance.FindByPK(CustomerID)).Name;
            }
            else
            {
                cusID = TextUtils.ToInt(grvCustomer.GetFocusedRowCellValue(colID));
                hang  = grvCustomer.GetFocusedRowCellValue(colCode).ToString();
            }

            if (cusID == 0)
            {
                MessageBox.Show("Bạn hãy chọn một hãng để up datasheet!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            int            count = 0;
            OpenFileDialog ofd   = new OpenFileDialog();

            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (string filePath in ofd.FileNames)
                {
                    ProcessTransaction pt = new ProcessTransaction();
                    pt.OpenConnection();
                    pt.BeginTransaction();
                    try
                    {
                        FileInfo          fInfo = new FileInfo(filePath);
                        MaterialFileModel fileModel;
                        bool isAdd = true;
                        if (MaterialFileBO.Instance.CheckExist("Name", Path.GetFileName(filePath)))
                        {
                            fileModel             = (MaterialFileModel)MaterialFileBO.Instance.FindByAttribute("Name", Path.GetFileName(filePath))[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 = fileModel.CreatedDate;
                            fileModel.UpdatedBy   = Global.AppUserName;
                        }

                        fileModel.Extension    = Path.GetExtension(filePath);
                        fileModel.Datemodified = fInfo.LastWriteTime;
                        fileModel.Length       = fInfo.Length;
                        fileModel.Name         = Path.GetFileName(fInfo.FullName);
                        fileModel.Path         = "Datasheet" + "/" + hang + "/" + Path.GetFileName(fInfo.FullName);
                        fileModel.IsDeleted    = false;
                        fileModel.FileType     = 1; //0 là file 3D cơ khí, 1 là datasheet
                        fileModel.CustormerID  = cusID;

                        if (isAdd)
                        {
                            pt.Insert(fileModel);
                        }
                        else
                        {
                            pt.Update(fileModel);
                        }

                        if (!DocUtils.CheckExits("Datasheet" + "/" + hang))
                        {
                            DocUtils.MakeDir("Datasheet" + "/" + hang);
                        }
                        DocUtils.UploadFile(filePath, "Datasheet" + "/" + hang);
                        pt.CommitTransaction();
                        count++;
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        pt.CloseConnection();
                    }
                }

                if (count > 0)
                {
                    loadGrid();
                }
            }
        }
示例#3
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();
                }
            }
        }
示例#4
0
 protected MaterialFileFacade(MaterialFileModel model) : base(model)
 {
 }