/// <summary> /// OK button click event /// </summary> private void btnOK_Click(object sender, EventArgs e) { // check input if (!CheckValidInput()) { return; } // create bat information _batInfo = new MkaBatInfo(); _batInfo.ChousaJisuu = Int32.Parse(txtChousaJisuu.Text.Trim()); _batInfo.OoChiku = txtOoChiku.Text.Trim(); _batInfo.ChuushouChiku = txtChuushouChiku.Text.Trim(); _batInfo.Ikoumei = txtIkoumei.Text.Trim(); _batInfo.Dosoumei = txtDosoumei.Text.Trim(); if (txtGrid.Text.Trim() == "") { _batInfo.Grid = 0; } else { _batInfo.Grid = Int32.Parse(txtGrid.Text.Trim()); } _batInfo.Date = dtpDate.Value; _batInfo.BatBangou = txtBatBangou.Text.Trim(); _batInfo.BatDirectory = Path.GetDirectoryName(txtImagePath.Text); // create glass information _glassInfo = new MkaGlassInfo(); _glassInfo.GlassItaBangou = txtGlassBangou.Text.Trim(); _glassInfo.ImageFilePath = txtImagePath.Text; _glassInfo.ImageFileName = Path.GetFileName(txtImagePath.Text); _glassInfo.GlassFilePath = Path.GetDirectoryName(txtImagePath.Text) + "\\" + Path.GetFileNameWithoutExtension(txtImagePath.Text) + MkaDefine.MkaFileExt; _glassInfo.KaishiRBangou = Int32.Parse(txtKaishiRBangou.Text.Trim()); _glassInfo.RFontSize = float.Parse(cmbFontSize.SelectedItem.ToString()); //update working directory DirectoryInfo wFolder = new DirectoryInfo(_glassInfo.GlassFilePath); MkaDefine.MokkanPath = wFolder.Parent.Parent.Parent.FullName; // check if existed if (File.Exists(_glassInfo.GlassFilePath)) { switch (MessageBox.Show(this, String.Format(MkaMessage.WarnExistedFile, _glassInfo.GlassFileName), MkaMessage.AppCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)) { case DialogResult.Yes: break; case DialogResult.No: return; case DialogResult.Cancel: this.DialogResult = DialogResult.Cancel; this.Close(); return; } } MkaBatInfo.LastBat = _batInfo; MkaMokkanInfo.LastRBangou = _glassInfo.KaishiRBangou; // store accessed path in registry RegistryKey key = MkaDefine.RootKey.CreateSubKey(MkaDefine.RegKey); key.SetValue(MkaDefine.RecentGlassPath, Path.GetDirectoryName(txtImagePath.Text)); // create new glass document _glassDoc = new MkaDocument(_owner); _glassDoc.Text = _glassInfo.GlassFileName; _glassDoc.GlassInfo = _glassInfo; _glassDoc.GlassImage = _glassInfo.ImageFilePath; _glassDoc.BatInfo = _batInfo; _glassDoc.Save(true); // Close form this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// Executing work /// </summary> private void bw_DoWork(object sender, DoWorkEventArgs e) { int iCount = _batPaths.Count; int _start = _startRId; for (int i = 0; i < iCount; i++) { // The Work to be performed... String _batPath = _batPaths[i]; String _batName = Path.GetFileName(_batPaths[i]); String _batFilePath = _batPath + "\\" + _batName + MkaDefine.BmkFileExt; FileOpenBat(_batFilePath); if (_batManager == null) { continue; } // Update the description and progress on the modal form // using Control.Invoke. Invoke will run the anonymous // function to set the label's text on the UI thread. // Since it's illegal to touch the UI control on the worker // thread that we're on right now. // Moron Anonymous functions: http://www.codeproject.com/books/cs2_anonymous_method.asp _fmProgress.LabelDescription.Invoke( (MethodInvoker) delegate() { _fmProgress.LabelDescription.Text = String.Format("実行 {0}_{1} ({2}/{3})...", _batManager.BatInfo.Grid, _batName, i + 1, iCount); _fmProgress.ProgressBar.Value = Convert.ToInt32((i + 1) * (100.0 / iCount)); } ); // change bat information if (ckbFileUpdate.Checked) { _batInfo = _batInfos.Find(delegate(BatInfo b) { return(b.Grid == _batManager.BatInfo.Grid); }); if (_batInfo != null) { _batManager.BatInfo.BatDirectory = _batPath; _batManager.BatInfo.BatBangou = _batName; _batManager.BatInfo.Grid = _batInfo.Grid; _batManager.BatInfo.ChousaJisuu = _batInfo.ChousaJisuu; _batManager.BatInfo.OoChiku = _batInfo.OoChiku; _batManager.BatInfo.ChuushouChiku = _batInfo.ChuushouChiku; _batManager.BatInfo.Ikoumei = _batInfo.Ikoumei; _batManager.BatInfo.Dosoumei = _batInfo.Dosoumei; _batManager.BatInfo.Date = _batInfo.Date; _batManager.Save(); } } List <string> _glassPaths = Directory.GetFiles(_batPath, "*" + MkaDefine.MkaFileExt).ToList(); _glassPaths.Sort(CompareGlass); int _sum = 0; foreach (String _glassPath in _glassPaths) { _activeDoc = FileLoadGlass(_glassPath); if (_activeDoc == null) { continue; } // change bat information if (ckbFileUpdate.Checked && _batInfo != null) { _activeDoc.BatInfo.BatDirectory = _batPath; _activeDoc.BatInfo.BatBangou = _batName; _activeDoc.BatInfo.Grid = _batInfo.Grid; _activeDoc.BatInfo.ChousaJisuu = _batInfo.ChousaJisuu; _activeDoc.BatInfo.OoChiku = _batInfo.OoChiku; _activeDoc.BatInfo.ChuushouChiku = _batInfo.ChuushouChiku; _activeDoc.BatInfo.Ikoumei = _batInfo.Ikoumei; _activeDoc.BatInfo.Dosoumei = _batInfo.Dosoumei; _activeDoc.BatInfo.Date = _batInfo.Date; } // change glass and mokkans' start id if (ckbFileUpdate.Checked && _startRIdSet) { _activeDoc.GlassInfo.KaishiRBangou = _start; _activeDoc.MokkanList.ReArrangeId(_start); } _activeDoc.Save(false); _start += _activeDoc.MokkanList.Count; _sum += _activeDoc.MokkanList.Count; _statWriter.WriteLine(String.Format("{0},{1},{2},{3},{4},{5}", _batManager.BatInfo.Grid, _batName, Path.GetFileNameWithoutExtension(_glassPath), _activeDoc.GlassInfo.KaishiRBangou, _activeDoc.GlassInfo.KaishiRBangou + _activeDoc.MokkanList.Count - 1, _activeDoc.MokkanList.Count)); } _statWriter.Flush(); if (_startRIdSet) { _statGlassWriter.WriteLine(String.Format("{0},{1},{2},{3},{4},{5}", _batManager.BatInfo.Grid, _batName, _batManager.GlassFileNames.Count, _startRId, _start - 1, _sum)); } else { _statGlassWriter.WriteLine(String.Format("{0},{1},{2},{3}", _batManager.BatInfo.Grid, _batName, _batManager.GlassFileNames.Count, _sum)); } _statGlassWriter.Flush(); // Periodically check for a Cancellation // If the user clicks the cancel button, or tries to close // the progress form the m_fmProgress.Cancel flag will be set to true. if (_fmProgress.Cancel) { // Set the e.Cancel flag so that the WorkerCompleted event // knows that the process was canceled. e.Cancel = true; return; } } }