private void listTextGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { string id = listTextGrid.Rows[e.RowIndex].Cells["id"].Value.ToString(); string prop = listTextGrid.Columns[e.ColumnIndex].DataPropertyName.ToString(); string newValue = listTextGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); StringObject foundStringObject = strings.FirstOrDefault(textObject => textObject.Id == id); if (foundStringObject == null || foundStringObject.Id == null) { MessageBox.Show("Not found!"); return; } foundStringObject.HasChanged = !newValue.Equals(foundStringObject.GetType().GetProperty("Origin" + prop).GetValue(foundStringObject).ToString()); if (foundStringObject.HasChanged) { RefreshGridView(); //listTextGrid.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(183, 85, 1, 100); //listTextGrid.Refresh(); } // Add to string objects // processor.AddOrUpdate(prop, ref strings, foundStringObject); } catch (Exception exception) { MessageBox.Show(Translate("0009", "Lỗi") + ": " + exception.Message); } }
private void RefreshGridView() { numberCountTxt.Text = listTextGrid.Rows.Count.ToString(); foreach (DataGridViewRow row in listTextGrid.Rows) { row.DefaultCellStyle.BackColor = Color.White; StringObject stringText = strings.FirstOrDefault(text => text.Id == row.Cells["id"].Value.ToString() && text.HasChanged == true); if (stringText != null && stringText.Id != null) { row.DefaultCellStyle.BackColor = Color.FromArgb(255, 195, 143); continue; } if (row.Index % 2 == 0) { row.DefaultCellStyle.BackColor = Color.FromArgb(255, 194, 233, 251); } if (row.Cells["En"] == null || row.Cells["En"].Value == null) { continue; } if (row.Cells["Vn"] == null || row.Cells["Vn"].Value == null) { continue; } if (row.Cells["En"].Value.ToString().Equals(row.Cells["Vn"].Value.ToString())) { row.DefaultCellStyle.BackColor = Color.FromArgb(255, 249, 220, 139); } } listTextGrid.Refresh(); }
public void AddOrUpdate(StringObject stringObj) { XmlNode stringsNode = node.SelectSingleNode("strings"); XmlNode existStringNode = stringsNode.SelectSingleNode(string.Format("string[@id='{0}']", stringObj.Id)); if (stringObj.En == null || stringObj.En.Equals("")) { if (existStringNode != null) { stringsNode.RemoveChild(existStringNode); doc.Save(this.path); } return; } // XmlNode existStringNode = stringsNode.SelectSingleNode(string.Format("string[@id='{0}']", stringObj.Id)); string textVal = stringObj.Vn; if (textVal == null || textVal.Equals("")) { textVal = stringObj.En; } if (existStringNode != null) { existStringNode.Attributes["text"].InnerText = textVal; } else { XmlElement newStringObjectNode = doc.CreateElement("string"); XmlAttribute newIdAttribute = doc.CreateAttribute("id"); XmlAttribute newTextAttribute = doc.CreateAttribute("text"); newIdAttribute.InnerText = stringObj.Id; newTextAttribute.InnerText = textVal; newStringObjectNode.SetAttributeNode(newIdAttribute); newStringObjectNode.SetAttributeNode(newTextAttribute); stringsNode.AppendChild(newStringObjectNode); doc.DocumentElement.AppendChild(stringsNode); } doc.Save(this.path); }
public void GetListStringData(string prop, ref SortedBindingList <StringObject> strings) { XmlNodeList li = node.SelectNodes("strings"); foreach (XmlNode item in li) { foreach (XmlNode stringNode in item.SelectNodes("string")) { int index = strings.Count; StringObject stringObject = new StringObject( index, stringNode.Attributes["id"].InnerText ); string originProp = "Origin" + prop; string text = stringNode.Attributes["text"].InnerText.ToString(); stringObject.SetData(prop, new MixedValue(text)); stringObject.SetData(originProp, new MixedValue(text)); AddOrUpdate(prop, ref strings, stringObject); } } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { try { StringObject modifiedString = strings.FirstOrDefault(textObject => textObject.HasChanged == true); if (modifiedString != null && modifiedString.Id != null) { DialogResult dialogResult = MessageBox.Show(LanguageResolver.Read("strings", "0007", "Có sự thay đổi dữ liệu. Bạn vẫn muốn thoát tool?"), LanguageResolver.Read("strings", "0008", "Nhắc nhở"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dialogResult == DialogResult.Yes) { Application.ExitThread(); } else { e.Cancel = true; } } } catch (Exception) { Application.ExitThread(); } }
public void AddOrUpdate(string prop, ref SortedBindingList <StringObject> strings, StringObject stringObject) { foreach (StringObject stringItem in strings) { if (stringItem.Id == stringObject.Id) { // SecurityElement.Escape(stringNode.Attributes["text"].InnerText) // No escape value stringItem.SetData(prop, new MixedValue(stringObject.GetType().GetProperty(prop).GetValue(stringObject, null))); return; } } strings.Add(stringObject); }