Ejemplo n.º 1
0
    public void UpdateCellEdit()
    {
        m_CellEditPanel.Visible      = false;
        m_CellEditTipPanel.Visible   = false;
        m_CellEditTextBox.Validated -= OnCellEditTextBox_Validated;

        if (SelCSVFormInitialized())
        {
            if (m_CSVForm.GetDataGridView().SelectedCells.Count == 0)
            {
                m_CellEditTipPanel.Visible = true;
                m_CellEditTipLabel.Text    = "当前未选中单元格";
            }
            else if (m_CSVForm.GetDataGridView().SelectedCells.Count == 1)
            {
                m_CellEditPanel.Visible = true;
                object value = m_CSVForm.GetDataGridView().SelectedCells[0].Value;
                m_CellEditTextBox.Text       = ((string)value).Replace("\n", "\r\n");
                m_CellEditTextBox.Validated += OnCellEditTextBox_Validated;
            }
            else if (m_CSVForm.GetDataGridView().SelectedCells.Count > 1)
            {
                m_CellEditTipPanel.Visible = true;
                m_CellEditTipLabel.Text    = "不支持编辑多个单元格";
            }
        }
        else
        {
            m_CellEditTipPanel.Visible = true;
            m_CellEditTipLabel.Text    = "";
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 合并文件
    /// </summary>
    private void MergeCsv(DataTable originalCSV, string[][] amCSV)
    {
        CSVForm csvForm = MainForm.Instance.GetCSVForm();

        csvForm.BeforeChangeCellValue();

        // 做的操作(用于撤销)
        m_DoManyThingList = new List <CSVEditManager.IUndoRedo>();
        m_CellChangeList  = new List <CSVEditManager.CellValueChangeItem>();
        m_MessageList     = new List <DataGridViewConsoleForm.Message>();

        // 遍历AM文件
        for (int iRowInAMCSV = 0; iRowInAMCSV < amCSV.Length; iRowInAMCSV++)
        {
            string[] iterAMRow = amCSV[iRowInAMCSV];
            // 这里Trim是为了匹配到源文件中的Key(Key头尾肯定不能用空白字符)
            string iterAMKey = iterAMRow[0].Trim();

            // 跳过空key,Key为空代表这行为空行
            if (string.IsNullOrWhiteSpace(iterAMKey))
            {
                continue;
            }
            // 如果key是String ID,是表头,直接无视
            if (iterAMKey.ToLower() == "String ID".ToLower())
            {
                continue;
            }
            // key中不能包含空格,跳过
            if (iterAMKey.Contains(" "))
            {
                DataGridViewConsoleForm.Message message = new DataGridViewConsoleForm.Message
                {
                    Level   = DataGridViewConsoleForm.Level.Warning,
                    Column  = 0,
                    Row     = iRowInAMCSV,
                    Caption = CSVEditor.Properties.Resources.MergeLocalizationToolAMCSVKeyContainsSpaceMessageCaption,
                    Text    = string.Format(CSVEditor.Properties.Resources.MergeLocalizationToolAMCSVKeyContainsSpaceMessageText, iterAMKey)
                };
                m_MessageList.Add(message);
                continue;
            }

            // 源文件中是否存在AM文件中的Key
            // 存在的话直接merge,不存在的话,把这一行添加到源文件结尾
            bool amKeyExistedInOriginal = false;
            for (int iRowInOriginalCSV = 0; iRowInOriginalCSV < originalCSV.Rows.Count; iRowInOriginalCSV++)
            {
                DataRow iterOriginalRow = originalCSV.Rows[iRowInOriginalCSV];
                string  iterOriginalKey = (string)iterOriginalRow[0];
                if (iterOriginalKey.Trim() == iterAMKey)
                {
                    amKeyExistedInOriginal = true;
                    MergeRow(iRowInOriginalCSV, iterAMRow, iterOriginalRow);
                    break;
                }
            }

            if (!amKeyExistedInOriginal)
            {
                // 添加新行
                DataRow newRow = originalCSV.NewRow();

                CSVEditManager.DoAddRowEvent doAddRowEvent = new CSVEditManager.DoAddRowEvent
                {
                    Row = originalCSV.Rows.Count
                };
                m_DoManyThingList.Add(doAddRowEvent);

                // Key
                newRow[0] = iterAMKey;
                CSVEditManager.CellValueChangeItem changeItem = new CSVEditManager.CellValueChangeItem
                {
                    Row      = originalCSV.Rows.Count,
                    Column   = 0,
                    OldValue = "",
                    NewValue = iterAMKey
                };
                m_CellChangeList.Add(changeItem);

                // 初始化值
                for (int iCell = 1; iCell < iterAMRow.Length; iCell++)
                {
                    newRow[iCell] = "";
                }

                MergeRow(originalCSV.Rows.Count, iterAMRow, newRow, true);
                originalCSV.Rows.Add(newRow);
            }
        }

        CSVEditManager.DoCellsValueChangeEvent doCellsValueChangeEvent = new CSVEditManager.DoCellsValueChangeEvent
        {
            ChangeList = m_CellChangeList
        };
        m_DoManyThingList.Add(doCellsValueChangeEvent);

        csvForm.EditManager.DidManyThings(m_DoManyThingList);
        csvForm.AfterChangeCellValue();
        csvForm.UpdateGridHeader();

        DataGridViewConsoleForm.ShowForm(m_MessageList, csvForm.GetDataGridView(), "本地化合并");
        Close();
    }