Пример #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if((radioButton1.Checked) || (radioButton2.Checked))
     {
         double sum = (double)numericUpDown1.Value + ((double)numericUpDown2.Value) / 100.0;
         if(sum > 0 )
         {
             Transaction tr = new Transaction();
             tr.setSum(sum);
             if (radioButton1.Checked)
                 tr.setType(1);
             else tr.setType(0);
             tr.setComent(textBox1.Text);
             MainManager.AddTransaction(tr);
             MainManager.FillAllTransactions();
             par.DrawAll();
             this.Close();
         }
         else
         {
             MessageBox.Show("Wrong transaction", "Error");
         }
     }
     else { MessageBox.Show("Fill Direction", "Error"); }
 }
Пример #2
0
 public static bool FillAllTransactions()
 {
     try
     {
         _history.Clear();
         dataBase.Load(@"" + pathToContent);
         XmlNodeList trans = dataBase.SelectNodes(@"//transaction");
         foreach(XmlNode node in trans)
         {
             Transaction transact = new Transaction();
             XmlAttributeCollection atributes = node.Attributes;
             int id = Convert.ToInt32(atributes[@"ID"].Value.ToString());
             if (id > maxId) maxId = id;
             transact.setID(id);
             string type = (atributes[@"TYPE"].Value.ToString());
             if (type == "IN")
                 transact.setType(1);
             else
                 transact.setType(0);
             transact.setSum(Convert.ToDouble(atributes[@"SUM"].Value.ToString()));
             balance = Convert.ToDouble(atributes[@"BALANCE"].Value.ToString());
             transact.setBalance(balance);
             transact.setComent(atributes[@"COMENT"].Value.ToString());
             XmlNodeList childs =  node.ChildNodes;
             transact.setDate(Convert.ToInt32(childs[0].Attributes[@"DAY"].Value.ToString()),
                              Convert.ToInt32(childs[0].Attributes[@"MONTH"].Value.ToString()),
                              Convert.ToInt32(childs[0].Attributes[@"YEAR"].Value.ToString())
                             );
             _history.Add(transact);
         }
     }
     catch (System.Exception) {
     MessageBox.Show("New DataBase was created", "Problems with database connection");
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(ar);
     doc.Save(@"" + pathToContent);
     //File.SetAttributes(@"" + pathToContent, File.GetAttributes(@"" + pathToContent) | FileAttributes.Hidden | (~FileAttributes.ReadOnly));
     FillAllTransactions();
     }
     return true;
 }
Пример #3
0
        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;
        }
Пример #4
0
        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();
        }