예제 #1
0
        void btnAddNewValues_Click(object sender, EventArgs e)
        {
            var checkedLanguages = this.clbLanguages.CheckedItems.Cast <Language>().ToList();
            var dgvStrings       = this.tlpStrings.GetControlFromPosition(0, 1) as DataGridView;

            using (var addNewValues = new AddEditValues(this, checkedLanguages.Select(l => l.Name).ToArray()))
                if (addNewValues.ShowDialog(this) == DialogResult.OK)
                {
                    int    rowNum      = dgvStrings.Rows.Add();
                    string key         = addNewValues.Values["Key"];
                    var    fileStrings = this.strings[this.lblFile.Text];
                    fileStrings[key]            = new Dictionary <string, string>();
                    dgvStrings[1, rowNum].Value = key;
                    for (int i = 0; i < checkedLanguages.Count; ++i)
                    {
                        var    cell       = dgvStrings[i + 2, rowNum];
                        string langString = addNewValues.Values[checkedLanguages[i].Name];
                        if (string.IsNullOrWhiteSpace(langString))
                        {
                            cell.Style.BackColor = Color.Yellow;
                        }
                        else
                        {
                            cell.Value = langString;
                            fileStrings[key][checkedLanguages[i].Value] = langString;
                        }
                    }
                    dgvStrings.Sort(dgvStrings.Columns[1], ListSortDirection.Ascending);
                }
        }
예제 #2
0
        void dgvStrings_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var dgvStrings = sender as DataGridView;

            if (dgvStrings.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                var    checkedLanguages = this.clbLanguages.CheckedItems.Cast <Language>().ToList();
                string originalKey      = dgvStrings[1, e.RowIndex].Value as string;
                using (var editValues = new AddEditValues(this, checkedLanguages.Select(l => l.Name).ToArray(), originalKey,
                                                          Enumerable.Range(2, checkedLanguages.Count).Select(i => dgvStrings[i, e.RowIndex].Value as string).ToArray()))
                    if (editValues.ShowDialog(this) == DialogResult.OK)
                    {
                        string newKey      = editValues.Values["Key"];
                        var    fileStrings = this.strings[this.lblFile.Text];
                        if (newKey != originalKey)
                        {
                            fileStrings.Remove(originalKey);
                            dgvStrings[1, e.RowIndex].Value = newKey;
                        }
                        if (!fileStrings.ContainsKey(newKey))
                        {
                            fileStrings[newKey] = new Dictionary <string, string>();
                        }
                        for (int i = 0; i < checkedLanguages.Count; ++i)
                        {
                            var    cell       = dgvStrings[i + 2, e.RowIndex];
                            string langString = editValues.Values[checkedLanguages[i].Name];
                            cell.Value = string.IsNullOrWhiteSpace(langString) ? null : langString;
                            if (string.IsNullOrWhiteSpace(langString))
                            {
                                cell.Style.BackColor = Color.Yellow;
                                fileStrings[newKey].Remove(checkedLanguages[i].Value);
                            }
                            else
                            {
                                cell.Style.BackColor = Color.White;
                                fileStrings[newKey][checkedLanguages[i].Value] = langString;
                            }
                        }
                        dgvStrings.Sort(dgvStrings.Columns[1], ListSortDirection.Ascending);
                    }
            }
        }