public static bool AddTransaction(Transaction tr) { File.SetAttributes(@"" + pathToContent, File.GetAttributes(@"" + pathToContent) & (~ FileAttributes.Hidden) & (~FileAttributes.ReadOnly)); dataBase.Load(@"" + pathToContent); XmlNodeList trans = dataBase.SelectNodes(@"//transaction"); XmlNode node = trans[0].Clone(); XmlAttributeCollection atributes = node.Attributes; maxId++; atributes[@"ID"].Value = maxId.ToString(); if (tr.getType() == 1) { atributes[@"TYPE"].Value = "IN"; balance += tr.getSum(); } else { atributes[@"TYPE"].Value = "OUT"; balance -= tr.getSum(); } atributes[@"COMENT"].Value = tr.getComent(); atributes[@"SUM"].Value = tr.getSum().ToString(); atributes[@"BALANCE"].Value = balance.ToString(); DateTime day = DateTime.Now; XmlNodeList childs = node.ChildNodes; childs[0].Attributes[@"DAY"].Value = day.Day.ToString(); childs[0].Attributes[@"MONTH"].Value = day.Month.ToString(); childs[0].Attributes[@"YEAR"].Value = day.Year.ToString(); XmlNode root = trans[0].ParentNode; root.AppendChild(node); try { dataBase.Save(@"" + pathToContent); } catch (System.Exception e) { MessageBox.Show(e.Message); } File.SetAttributes(@"" + pathToContent, File.GetAttributes(@"" + pathToContent) | FileAttributes.Hidden); return true; }
private void AddTransactionToTable(Transaction tr) { int index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[@"ID"].Value = tr.getID().ToString(); string str = tr.getMonth().ToString(); if (str.Length < 2) str = "0" + str; dataGridView1.Rows[index].Cells[@"Date"].Value = tr.getDay().ToString() + "." + str + "." + tr.getYear().ToString(); if(tr.getType() == 1) dataGridView1.Rows[index].Cells[@"Type"].Value = "IN"; else dataGridView1.Rows[index].Cells[@"Type"].Value = "OUT"; double sum = tr.getSum(); str = (Math.Abs(((int)(sum * 100)) % 100)).ToString(); if (str.Length < 2) str = "0" + str; dataGridView1.Rows[index].Cells[@"Sum"].Value = ((int)sum).ToString() + "." + str; sum = tr.getBalance(); str = (Math.Abs(((int)(sum * 100)) % 100)).ToString(); if (str.Length < 2) str = "0" + str; dataGridView1.Rows[index].Cells[@"Balance"].Value = ((int)sum).ToString() + "." + str; dataGridView1.Rows[index].Cells[@"Coment"].Value = tr.getComent(); dataGridView1.Refresh(); }