Beispiel #1
0
        void FrmModelSet_Load(object sender, EventArgs e)
        {
            this.Enabled = false;
            RIPP.NIR.Controls.StyleTool.FormatGrid(ref this.dataGridView1);
            if (this._user.Role == RoleEnum.Operater)
            {
                this.dataGridView1.Columns[1].Visible = false;
                this.btnDel.Enabled    = false;
                this.btnImport.Enabled = false;
            }

            Action a = () =>
            {
                string modelPath = this._config.FolderModel;
                if (!Directory.Exists(modelPath))
                {
                    Directory.CreateDirectory(modelPath);
                }
                string fileter = string.Format("*.{0}|*.{1}|*.{2}|*.{3}|*.{4}",
                                               FileExtensionEnum.Allmethods,
                                               FileExtensionEnum.FitLib,
                                               FileExtensionEnum.IdLib,
                                               FileExtensionEnum.PLSBind,
                                               FileExtensionEnum.ItgBind
                                               );
                string[] files = GetFiles(
                    modelPath,
                    fileter,
                    SearchOption.TopDirectoryOnly);

                for (int i = 0; i < files.Length; i++)
                {
                    try
                    {
                        var model = BindModel.LoadModel(files[i]);
                        if (this._config.AvailableModelNames.Contains((new FileInfo(files[i]).Name)) || this._user.Role != RoleEnum.Operater)
                        {
                            this.addRow(model);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (this.InvokeRequired)
                {
                    ThreadStart s = () => { this.Enabled = true; };
                    this.Invoke(s);
                }
                else
                {
                    this.Enabled = true;
                }
            };

            a.BeginInvoke(null, null);
        }
Beispiel #2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog myOpenFileDialog = new OpenFileDialog();

            myOpenFileDialog.Filter = string.Format("所有方法文件 (*.{0};*.{2};*.{4};*.{6};*.{8})|*.{0};*.{2};*.{4};*.{6};*.{8}|{1} (*.{0})|*.{0}|{3} (*.{2})|*.{2}|{5} (*.{4})|*.{4}|{7} (*.{6})|*.{6}|{9} (*.{8})|*.{8}",
                                                    FileExtensionEnum.Allmethods,
                                                    FileExtensionEnum.Allmethods.GetDescription(),
                                                    FileExtensionEnum.IdLib,
                                                    FileExtensionEnum.IdLib.GetDescription(),
                                                    FileExtensionEnum.FitLib,
                                                    FileExtensionEnum.FitLib.GetDescription(),
                                                    FileExtensionEnum.PLSBind,
                                                    FileExtensionEnum.PLSBind.GetDescription(),
                                                    FileExtensionEnum.ItgBind,
                                                    FileExtensionEnum.ItgBind.GetDescription()
                                                    );
            myOpenFileDialog.Title = "选择方法包";
            myOpenFileDialog.Title = this._config.FolderModel;
            if (myOpenFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            BindModel m = null;

            try
            {
                m          = BindModel.LoadModel(myOpenFileDialog.FileName);
                m.FullPath = myOpenFileDialog.FileName;
            }
            catch
            {
                MessageBox.Show("该文件有误,请选择其它文件", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                //复制
                var    finfo   = new FileInfo(myOpenFileDialog.FileName);
                string newfile = Path.Combine(this._config.FolderModel, finfo.Name);
                var    tag     = true;
                if (File.Exists(newfile))
                {
                    if (MessageBox.Show("提示信息", "已经有相同名称的方法存在,是否替换?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
                    {
                        tag = false;
                    }
                }
                if (tag)
                {
                    File.Copy(myOpenFileDialog.FileName, newfile, true);
                    var newfileinfo = new FileInfo(newfile);
                    var oldfolder   = finfo.FullName.Replace(finfo.Extension, "");
                    var newfolder   = newfileinfo.FullName.Replace(newfileinfo.Extension, "");
                    if (Directory.Exists(oldfolder))
                    {
                        if (Directory.Exists(newfolder))
                        {
                            RIPP.Lib.Tool.DeleteFolder(newfolder);
                        }
                        RIPP.Lib.Tool.CopyDirectory(oldfolder, this._config.FolderModel);
                    }
                    //加载表格
                    this.addRow(m);
                    this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Selected = true;
                }
            }
        }