private void newSessionButton_Click(object sender, EventArgs e) { sessionType = 1; StartupName GetFileName = new StartupName(); GetFileName.ShowDialog(); dbFile = GetFileName.sessionNameTextBx.Text + GetFileName.startYearTextBox.Text; GetFileName.Dispose(); GetFileName.Visible = false; StartupBudget GetBudgetInfo = new StartupBudget(); GetBudgetInfo.ShowDialog(); NewBudgetInfo = GetBudgetInfo.BudgetInfo; GetBudgetInfo.Dispose(); Dispose(); }
public Graphs(List<string> items, Budget BudgetVals, int curMonth,string curDB) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); //string dbSource = "DataSource="+curDB; DBConnection = new db(curDB); commandValue = "Select Category,ShowChart from BudgetInfo;"; DBConnection.ExecuteQuery(commandValue); while (DBConnection.QueryStep()) { if (System.Convert.ToBoolean(DBConnection.QueryReturnInt(1))) { budgetItemList.Add(DBConnection.QueryReturnString(0)); } } dbSelectCombo.Items.AddRange(budgetItemList.ToArray()); dbSelectCombo.SelectedIndex = 8; BudgetInfo = BudgetVals; //budgetItemList = items; month = curMonth+1; // for (int i = 0; i < 12; i++) { Months.Add(monthValsAbbr[i]); } commandValue = "select Amount from BudgetInfo where DatabaseIndex=0"; //commandValue += category.ToString(); targetValue = DBConnection.ReturnTotals(commandValue); UpdateChart(8); }
public void WriteData(string StartPath, int month, int year, Budget BudgetVals) { // Create a new file in C:\\ dir XmlTextWriter textWriter = new XmlTextWriter(StartPath + "\\checkbook.xml", null); // Opens the document textWriter.WriteStartDocument(); // Write comments textWriter.WriteComment("Checkbook initialization"); textWriter.WriteComment("checkbook.xml"); textWriter.Formatting = Formatting.Indented; // Write first element textWriter.WriteStartElement("Checkbook"); textWriter.WriteStartElement("Date"); // Write next element textWriter.WriteStartElement("Month", ""); textWriter.WriteString(month.ToString()); textWriter.WriteEndElement(); // Write one more element textWriter.WriteStartElement("Year", ""); textWriter.WriteString(year.ToString()); textWriter.WriteEndElement(); textWriter.WriteEndElement(); // Write first element textWriter.WriteStartElement("Budget"); for (int i = 0;i < BudgetVals.numBudget;i++) { textWriter.WriteStartElement("Category",""); textWriter.WriteStartElement("Name",""); textWriter.WriteString(BudgetVals.budgetCategories[i].ToString()); textWriter.WriteEndElement(); textWriter.WriteStartElement("Amount",""); textWriter.WriteString(BudgetVals.budgetedAmount[i].ToString()); textWriter.WriteEndElement(); if (BudgetVals.verificationPerYear[i] < 1) { textWriter.WriteStartElement("Verify",""); textWriter.WriteString("0"); textWriter.WriteEndElement(); textWriter.WriteStartElement("NumVerifications",""); textWriter.WriteString("0"); textWriter.WriteEndElement(); textWriter.WriteStartElement("VerificationDate",""); textWriter.WriteString("0"); textWriter.WriteEndElement(); textWriter.WriteStartElement("VerificationMonthStart",""); textWriter.WriteString("0"); textWriter.WriteEndElement(); } else { textWriter.WriteStartElement("Verify",""); textWriter.WriteString("1"); textWriter.WriteEndElement(); textWriter.WriteStartElement("NumVerifications",""); textWriter.WriteString(BudgetVals.verificationPerYear[i].ToString()); textWriter.WriteEndElement(); textWriter.WriteStartElement("VerificationDate",""); textWriter.WriteString(BudgetVals.verificationDate[i].ToString()); textWriter.WriteEndElement(); textWriter.WriteStartElement("VerificationMonthStart",""); textWriter.WriteString(BudgetVals.monthStart[i].ToString()); textWriter.WriteEndElement(); } textWriter.WriteEndElement(); } textWriter.WriteEndElement(); // Ends the document. textWriter.WriteEndDocument(); // close writer textWriter.Close(); }
public void ExcelExport(int sheet, int cells, Budget budgetClass, string path,int year) { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range xlRange; //Excel.Application xlApp; //Excel.Workbook xlWorkBook; //Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; try { xlApp = new Excel.ApplicationClass(); //xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(misValue); string workbookPath = path + "budgeting" + year.ToString() + ".xls"; //xlWorkBook = xlApp.Workbooks.Open(workbookPath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);// try { xlWorkBook = xlApp.Workbooks.Open(workbookPath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);//, //misValue, //misValue); } catch (Exception e) { Console.WriteLine(e); xlWorkBook.SaveAs(workbookPath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue);//, //misValue);// xlWorkBook = xlApp.Workbooks.Open(workbookPath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);//, //misValue, //misValue); } //xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(sheet); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(sheet); //the column must be + 3 due to the month starting at 0 and the columns being 1 //and then having a label and a budgeted amount column //the rows start at 1 also which means you have to add 2 to the row for //the label //Re-add in all the data just in case it has never been put in. xlWorkSheet.Cells[1,1] = "Budget Cat"; xlWorkSheet.Cells[1,2] = "Budget Amt"; xlWorkSheet.Cells[1,3] = "January"; xlWorkSheet.Cells[1,4] = "February"; xlWorkSheet.Cells[1,5] = "March"; xlWorkSheet.Cells[1,6] = "April"; xlWorkSheet.Cells[1,7] = "May"; xlWorkSheet.Cells[1,8] = "June"; xlWorkSheet.Cells[1,9] = "July"; xlWorkSheet.Cells[1,10] = "August"; xlWorkSheet.Cells[1,11] = "September"; xlWorkSheet.Cells[1,12] = "October"; xlWorkSheet.Cells[1,13] = "November"; xlWorkSheet.Cells[1,14] = "December"; SQLiteConnection connector = new SQLiteConnection("Data Source=2013Tomo.d"); connector.Open(); SQLiteCommand mycommand = new SQLiteCommand(connector); SQLiteDataReader reader; for (int i=0;i<budgetClass.totalBudget;i++) { xlWorkSheet.Cells[i+2, 1] = budgetClass.budgetCategories[i]; } for (int i=0;i<budgetClass.totalBudget;i++) { xlWorkSheet.Cells[i+2, 2] = budgetClass.budgetedAmount[i]; } for (int month=0;month<12;month++) { for (int i=0;i<budgetClass.totalBudget;i++) { string command = "select Total(Amount) from Transactions where Category="; command += i.ToString(); command += " and month="+month.ToString(); mycommand.CommandText = command; reader = mycommand.ExecuteReader(); reader.Read(); float amountValue = System.Convert.ToSingle(reader[0]); mycommand.Dispose(); command = "select Total(Amount) from AmazonTransactions where Category="; command += i.ToString(); command += " and month="+month.ToString(); mycommand.CommandText = command; reader = mycommand.ExecuteReader(); reader.Read(); float amountValue2 = System.Convert.ToSingle(reader[0]); mycommand.Dispose(); xlWorkSheet.Cells[i+2, month+3] = amountValue-amountValue2;//budgetClass.budgetSpentAmount[i]; } } for (int i=0;i<budgetClass.totalBudget;i++) { string command = "select Total(Amount) from Transactions where Category="; command += i.ToString(); mycommand.CommandText = command; reader = mycommand.ExecuteReader(); reader.Read(); float amountValue = System.Convert.ToSingle(reader[0]); mycommand.Dispose(); command = "select Total(Amount) from AmazonTransactions where Category="; command += i.ToString(); mycommand.CommandText = command; reader = mycommand.ExecuteReader(); reader.Read(); float amountValue2 = System.Convert.ToSingle(reader[0]); mycommand.Dispose(); xlWorkSheet.Cells[i+2, 15] = amountValue-amountValue2;//budgetClass.budgetSpentAmount[i]; } connector.Close(); // Set the range to fill. xlRange = xlWorkSheet.get_Range("A1", "E100"); xlRange.Columns.AutoFit(); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } catch (Exception COMException) { Console.Write("COMException"+COMException); } }