Beispiel #1
0
 /// <summary>
 /// Activate document to edit property
 /// </summary>
 public void SelectDoc(MkaDocument doc)
 {
     this.DocumentArea = doc;
     this.MokkanList   = doc.MokkanList;
     if (MokkanList.SelectionCount > 0)  // mokkan property
     {
         this.propertyGrid.SelectedObjects = MokkanList.SelectedObjectsProperties;
         SelectedType = SelectedObjectType.Mokkan;
     }
     else    // glass property
     {
         this.propertyGrid.SelectedObject = doc.GlassInfo;
         SelectedType = SelectedObjectType.Glass;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Load glass information from xml file
        /// </summary>
        private MkaDocument FileLoadGlass(String filename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            // Deserialize object from xml format
            IXmlFormatter formatter = FepXmlableFactory.CreateXmlFormatter();
            IXmlContext   cnt       = FepXmlableFactory.CreateXmlContext(formatter, doc);

            XmlElement  _eleBat   = cnt.Document.DocumentElement;
            XmlNode     _eleGlass = _eleBat.FirstChild;
            XmlNode     _eleMk    = _eleGlass.FirstChild;
            MkaDocument mkaDoc    = new MkaDocument(null);

            mkaDoc.GlassInfo               = cnt.FromXml(_eleGlass as XmlElement) as MkaGlassInfo;
            mkaDoc.BatInfo                 = cnt.FromXml(_eleBat as XmlElement) as MkaBatInfo;
            mkaDoc.MokkanList              = cnt.FromXml(_eleMk as XmlElement) as MokkanList;
            mkaDoc.BatInfo.BatDirectory    = Path.GetDirectoryName(filename);
            mkaDoc.GlassInfo.GlassFilePath = filename;
            mkaDoc.GlassInfo.MokkanKazu    = mkaDoc.MokkanList.Count;
            mkaDoc.GlassImage              = Path.GetDirectoryName(filename) + "\\" + mkaDoc.GlassInfo.ImageFileName;

            int maxRid = mkaDoc.MokkanList.GetMaxRBangou() + 1;

            if (maxRid == 1)
            {
                MkaMokkanInfo.LastRBangou = mkaDoc.GlassInfo.KaishiRBangou;
            }
            else
            {
                MkaMokkanInfo.LastRBangou = maxRid;
            }
            mkaDoc.MokkanList.KaishiRBangou = MkaMokkanInfo.LastRBangou;

            return(mkaDoc);
        }
Beispiel #3
0
        /// <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();
        }
Beispiel #4
0
        /// <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;
                }
            }
        }