示例#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    = "";
        }
    }
示例#2
0
    private void Merge(DataTable originalCsv, string[][] changedCsv)
    {
        CsvForm csvForm = MainForm.Instance.GetCsvForm();

        csvForm.BeforeChangeCellValue();

        m_ManyThingList  = new List <CsvEditManager.IUndoRedo>();
        m_CellChangeList = new List <CsvEditManager.CellValueChangeItem>();
        m_MessageList    = new List <DataGridViewConsoleForm.Message>();

        for (int iRowInChangedCSV = 0; iRowInChangedCSV < changedCsv.Length; iRowInChangedCSV++)
        {
            string[] changedDataInRow = changedCsv[iRowInChangedCSV];

            string key = changedDataInRow[0];
            changedDataInRow[0] = key.Trim();
            // 跳过空key
            if (string.IsNullOrWhiteSpace(key))
            {
                continue;
            }
            // 为什么要把Trim的结果赋值回changedDataInRow[0]?
            // 因为changedCSV的key中有可能出现空格或换行符,工具生成的CSV文件中的新增和修改的部分都是直接用changedCSV里的内容,所以需要把changedCSV里的keyTrim一下
            if (key.Trim() == "String ID")
            {
                // 如果key是String ID,则是表头,直接无视
                continue;
            }

            bool existed = false;
            for (int iRowInOriginalCSV = 0; iRowInOriginalCSV < originalCsv.Rows.Count; iRowInOriginalCSV++)
            {
                DataRow originalDataInRow = originalCsv.Rows[iRowInOriginalCSV];
                string  originalKey       = (string)originalDataInRow[0];
                if (originalKey.Trim() == key.Trim())
                {
                    // key前后有空格
                    if (key != key.Trim())
                    {
                        DataGridViewConsoleForm.Message message = new DataGridViewConsoleForm.Message();
                        message.Level   = DataGridViewConsoleForm.Level.Warning;
                        message.Column  = 0;
                        message.Row     = iRowInOriginalCSV;
                        message.Caption = "Key的头尾有空白字符";
                        message.Text    = string.Format("我帮你去除了空格\n去空格前的Key:({0})", key);
                        m_MessageList.Add(message);
                    }

                    existed = true;
                    CopyCsvRowToDataRow(iRowInOriginalCSV, changedDataInRow, originalDataInRow);
                    break;
                }
            }

            if (!existed)
            {
                // 添加新行
                DataRow newRow = originalCsv.NewRow();
                for (int iCell = 0; iCell < changedDataInRow.Length; iCell++)
                {
                    newRow[iCell] = "";
                }
                CsvEditManager.DoAddRowEvent doAddRowEvent = new CsvEditManager.DoAddRowEvent
                {
                    Row = originalCsv.Rows.Count
                };
                m_ManyThingList.Add(doAddRowEvent);

                CopyCsvRowToDataRow(originalCsv.Rows.Count, changedDataInRow, newRow);
                originalCsv.Rows.Add(newRow);
            }
        }

        CsvEditManager.DoCellsValueChangeEvent doCellsValueChangeEvent = new CsvEditManager.DoCellsValueChangeEvent
        {
            ChangeList = m_CellChangeList
        };
        m_ManyThingList.Add(doCellsValueChangeEvent);

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

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