Example #1
0
        /// <summary>
        /// 单选按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rbtn_Click(object sender, EventArgs e)
        {
            RadioButton radio = (RadioButton)sender;
            bool        check = radio.Checked;

            if (radio.Name == this.rbtnLower.Name)
            {
                Invokes.SetRadioButtonChecked(this.rbtnLower, !check);
                check = Invokes.GetRadioButtonChecked(this.rbtnUpper);
                Invokes.SetRadioButtonChecked(this.rbtnUpper, check ? false : check);
            }
            else
            {
                Invokes.SetRadioButtonChecked(this.rbtnUpper, !check);
                check = Invokes.GetRadioButtonChecked(this.rbtnLower);
                Invokes.SetRadioButtonChecked(this.rbtnLower, check ? false : check);
            }
        }
Example #2
0
 private void setRadioButton()
 {
     Invokes.SetRadioButtonChecked(radioButton1, !Invokes.GetRadioButtonChecked(radioButton1));
 }
Example #3
0
 private void getRadioButton()
 {
     MessageBox.Show(Invokes.GetRadioButtonChecked(radioButton1).ToString());
 }
Example #4
0
        /// <summary>
        /// 开始执行按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                int progress = 1;
                this.TextBoxTime_Leave(this.tbCreateTime, null);
                this.TextBoxTime_Leave(this.tbModifiedTime, null);
                SetProgressBarVisible(true);
                UpdateProgressBar(0, 0, 0);

                if (this._files == null || this._dir == null)
                {
                    Msg("未选择文件");
                    return;
                }

                if (string.IsNullOrEmpty(this.tbReplacedText.Text.Trim()) &&
                    string.IsNullOrEmpty(this.tbReName.Text.Trim()) &&
                    !this.rbtnLower.Checked && !this.rbtnUpper.Checked &&
                    string.IsNullOrEmpty(this.tbCreateTime.Text) &&
                    string.IsNullOrEmpty(this.tbModifiedTime.Text))
                {
                    Msg("请填写操作参数:替换或者重命名相关信息");
                    return;
                }

                if (this.cbBak.Checked)
                {
                    string tmpPath = _dir + "tmp\\";
                    if (!Directory.Exists(tmpPath))
                    {
                        Directory.CreateDirectory(tmpPath);
                    }

                    foreach (FileInfos file in _files)
                    {
                        Msg("备份中:" + progress + "/" + _files.Count);
                        UpdateProgressBar(progress, 1, _files.Count);
                        File.Copy(_dir + file.Name, tmpPath + file.Name, true);
                        progress++;
                    }
                }

                Msg("重命名中……");
                List <FileInfos> fileList = new List <FileInfos>();

                int counter = 0;

                //0:不修改;1:替换;2:重命名;
                int type = 0;
                progress = 1;
                if (!string.IsNullOrEmpty(this.tbReName.Text.Trim()))
                {
                    type    = 2;
                    counter = (int)this.nudStart.Value;
                    var max = Math.Pow(10, (double)this.nudBit.Value) - 1;
                    if (this._files.Count > (max - (int)this.nudStart.Value))
                    {
                        Msg("序号位数最大值小于所选文件数,请更正序号位数");
                        return;
                    }
                }
                else if (!string.IsNullOrEmpty(this.tbReplacedText.Text.Trim()))
                {
                    type = 1;
                }

                bool extUpper = Invokes.GetRadioButtonChecked(this.rbtnUpper);
                bool extLower = Invokes.GetRadioButtonChecked(this.rbtnLower);

                foreach (FileInfos info in _files)
                {
                    string tmp = info.SafeName;
                    if (type == 1)//替换
                    {
                        tmp = info.SafeName.Replace(this.tbReplacedText.Text.Trim(), this.tbReplaceText.Text.Trim());
                    }
                    else if (type == 2)//重命名-序号
                    {
                        tmp = this.tbReName.Text.Trim() +
                              this.tbConnector.Text.Trim() +
                              this.GetSerial(counter, (int)this.nudBit.Value);
                    }

                    if (File.Exists(info.FullName))
                    {
                        Msg("重命名中:" + progress + "/" + _files.Count);
                        UpdateProgressBar(progress, 1, _files.Count);
                        string _ext = info.Ext;
                        if (!string.IsNullOrEmpty(_ext))
                        {
                            if (extUpper)
                            {
                                _ext = _ext.ToUpper();
                            }
                            else if (extLower)
                            {
                                _ext = _ext.ToLower();
                            }
                        }

                        FileInfos _info = new FileInfos();
                        _info.Dir      = info.Dir;
                        _info.Ext      = _ext;
                        _info.SafeName = tmp;
                        _info.Name     = tmp + _ext;
                        _info.FullName = info.Dir + tmp + _ext;
                        fileList.Add(_info);

                        FileInfo file = new FileInfo(info.FullName);
                        if (_createTime != null)
                        {
                            file.CreationTime   = (DateTime)_createTime;
                            file.LastAccessTime = (DateTime)_createTime;
                        }
                        if (_modifiedTime != null)
                        {
                            file.LastWriteTime  = (DateTime)_modifiedTime;
                            file.LastAccessTime = (DateTime)_modifiedTime;
                        }
                        file.MoveTo(_info.FullName);
                    }
                    progress++;
                    counter++;
                }
                Msg("重命名完成");
                _files = fileList;
                FilesListInit();
                this.tbReplaceText.Text  = "";
                this.tbReplacedText.Text = "";
                this.tbReName.Text       = "";
                this.tbConnector.Text    = "";
            }
            catch (Exception ex)
            {
                Msg("发生异常");
            }
            finally
            {
                SetProgressBarVisible(false);
                UpdateProgressBar(0, 0, 0);
                this.Cursor = Cursors.Default;
            }
        }