private void button_save_Click(object sender, EventArgs e) { Calendar calendar = new Calendar(); calendar.date = DateTime.Parse(groupBox_info.Text); calendar.flows = new ArrayList(); foreach (DataGridViewRow row in dataGridView_info.Rows) { if (!row.ReadOnly && !row.IsNewRow && row.Cells[0].Value != null && row.Cells[1].Value != null) { double volume; if (!double.TryParse(row.Cells[1].Value.ToString(), out volume)) { MessageBox.Show("输入数据异常!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { Flow flow = new Flow(); flow.type = ((DataGridViewComboBoxCell)row.Cells[0]).Value.ToString() == "0" ? FlowType.income : FlowType.payout; flow.volume = volume; flow.comment = row.Cells[2].Value == null ? "" : row.Cells[2].Value.ToString(); calendar.flows.Add(flow); } } } foreach (Calendar c in Form_Main.ar_Calendars) { if (c.date == calendar.date) { Form_Main.ar_Calendars.Remove(c); break; } } Form_Main.ar_Calendars.Add(calendar); try { Xml.UpdateCalendar(Form_Main.file_Calendars, Form_Main.ar_Calendars); MessageBox.Show(groupBox_info.Text + " 数据保存成功!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(groupBox_info.Text + " 数据保存失败!\n\n" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_saveincome_Click(object sender, EventArgs e) { if (DialogResult.Yes == MessageBox.Show("确认修改本月收入信息?", "确认修改", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { DataGridView dgv = (sender as Button).Parent.Controls["dataGridView_income"] as DataGridView; DateTime curMonth = DateTime.Parse((dgv.Parent.Parent.Parent as GroupBox).Text); for (int i = 0; i < ar_Calendars.Count; i++) { Calendar c = (Calendar)ar_Calendars[i]; if (c.date.Year == curMonth.Year && c.date.Month == curMonth.Month) { ArrayList newflows = new ArrayList(); for (int j = 0; j < c.flows.Count; j++) { Flow f = (Flow)c.flows[j]; if (f.type == FlowType.income) { c.flows.Remove(f); j--; } } } } try { foreach (DataGridViewRow row in dgv.Rows) { if (!row.ReadOnly && !row.IsNewRow) { Calendar calendar = new Calendar(); calendar.date = new DateTime(curMonth.Year, curMonth.Month, int.Parse(row.Cells[0].Value.ToString())); Flow flow = new Flow(); flow.type = FlowType.income; flow.volume = double.Parse(row.Cells[1].Value.ToString()); flow.comment = row.Cells[2].Value == null ? "" : row.Cells[2].Value.ToString(); foreach (Calendar existC in ar_Calendars) { if (existC.date == calendar.date) { existC.flows.Add(flow); calendar.date = new DateTime(1000, 1, 1); break; } } if (calendar.date.Year != 1000) { calendar.flows = new ArrayList(); calendar.flows.Add(flow); ar_Calendars.Add(calendar); } } } Xml.UpdateCalendar(file_Calendars, ar_Calendars); MessageBox.Show("收入信息保存成功!", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information); Reload(); } catch (Exception ex) { MessageBox.Show("收入信息保存失败!\n\n" + ex.Message, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static ArrayList LoadCalendar(string file) { ArrayList calendars = new ArrayList(); XmlDocument xml = new XmlDocument(); xml.Load(file); XmlNode root = xml.SelectSingleNode("Calendar"); foreach (XmlNode year in root.ChildNodes) { foreach (XmlNode month in year.ChildNodes) { foreach (XmlNode day in month.ChildNodes) { Calendar calendar = new Calendar(); calendar.date = new DateTime(int.Parse(year.Attributes["value"].Value), int.Parse(month.Attributes["value"].Value), int.Parse(day.Attributes["value"].Value)); calendar.flows = new ArrayList(); foreach (XmlNode flow in day.ChildNodes) { Flow f = new Flow(); f.type = (FlowType)(Enum.ToObject(typeof(FlowType), byte.Parse(flow.Attributes["type"].Value))); f.volume = double.Parse(flow.Attributes["volume"].Value); f.comment = flow.Attributes["comment"].Value; calendar.flows.Add(f); } // filter for empty day if (calendar.flows.Count > 0) calendars.Add(calendar); } } } return calendars; }
private void Form_Calendar_Load(object sender, EventArgs e) { DateTime start = new DateTime(toMonth.Year,toMonth.Month,1); DateTime end = start.AddDays(1 - start.Day).AddMonths(1).AddDays(-1); int intervel; // loop partners' paybacks // loop projects' paybacks // loop debts' outputs // loop calendar's comments // the generated rows are readonly foreach (Partner partner in Form_Main.ar_Partners) { foreach (Fund fund in partner.funds) { if (fund.start < start && fund.end >= start) { switch (fund.cycle) { case Cycle.monthly: intervel = 1; break; case Cycle.seasonly: intervel = 3; break; case Cycle.halfyearly: intervel = 6; break; case Cycle.yearly: intervel = 12; break; case Cycle.undefined: default: intervel = 0; break; } if (intervel == 0) continue; else { if (((toMonth.Year - fund.start.Year) * 12 + toMonth.Month - fund.start.Month) % intervel == 0) { Calendar c = new Calendar(); c.date = new DateTime(toMonth.Year, toMonth.Month, fund.start.Day); c.flows = new ArrayList(); Flow flow = new Flow(); flow.type = FlowType.payout; flow.volume = fund.volume * fund.rate * intervel / 12f; flow.comment = "股东\"" + partner.name + "\"资金(" + fund.volume + "万)结息"; c.flows.Add(flow); monthInfo.Add(c); } } } } } foreach (Project project in Form_Main.ar_Projects) { if (project.start < start && project.end >= start) { switch (project.cycle) { case Cycle.monthly: intervel = 1; break; case Cycle.seasonly: intervel = 3; break; case Cycle.halfyearly: intervel = 6; break; case Cycle.yearly: intervel = 12; break; case Cycle.undefined: default: intervel = 0; break; } if (intervel == 0) continue; else { if (((toMonth.Year - project.start.Year) * 12 + toMonth.Month - project.start.Month) % intervel == 0) { Calendar c = new Calendar(); c.date = new DateTime(toMonth.Year, toMonth.Month, project.start.Day); c.flows = new ArrayList(); Flow flow = new Flow(); flow.type = FlowType.income; flow.volume = project.volume * project.rate * intervel / 12f; flow.comment = "投资\"" + project.name + "\"资金(" + project.volume + "万)结息"; c.flows.Add(flow); monthInfo.Add(c); } } } } foreach (Debt debt in Form_Main.ar_Debts) { if (debt.start < start && debt.end >= start) { switch (debt.cycle) { case Cycle.monthly: intervel = 1; break; case Cycle.seasonly: intervel = 3; break; case Cycle.halfyearly: intervel = 6; break; case Cycle.yearly: intervel = 12; break; case Cycle.undefined: default: intervel = 0; break; } if (intervel == 0) continue; else { if (((toMonth.Year - debt.start.Year) * 12 + toMonth.Month - debt.start.Month) % intervel == 0) { Calendar c = new Calendar(); c.date = new DateTime(toMonth.Year, toMonth.Month, debt.start.Day); c.flows = new ArrayList(); Flow flow = new Flow(); flow.type = FlowType.payout; flow.volume = debt.volume; flow.comment = "生活支出\"" + debt.name + "\"资金(" + debt.volume + "万)支出"; c.flows.Add(flow); monthInfo.Add(c); } } } } bool exist = false; foreach (Calendar calendar in monthInfo) { Label label = new Label(); label.AutoSize = true; label.Text = calendar.date.Day.ToString(); label.Cursor = Cursors.Hand; label.Click += new EventHandler(l_Click); if (((Flow)calendar.flows[0]).type == FlowType.income) { exist = false; foreach (Label l in flowLayoutPanel_in.Controls) { if (l.Text == label.Text) exist = true; } if (!exist) flowLayoutPanel_in.Controls.Add(label); } else if (((Flow)calendar.flows[0]).type == FlowType.payout) { exist = false; foreach (Label l in flowLayoutPanel_out.Controls) { if (l.Text == label.Text) exist = true; } if (!exist) flowLayoutPanel_out.Controls.Add(label); } else { } } foreach (Calendar calendar in Form_Main.ar_Calendars) { if (calendar.date >= start && calendar.date <= end) { foreach (Flow flow in calendar.flows) { Label l = new Label(); l.ForeColor = Color.Blue; l.AutoSize = true; l.Text = calendar.date.Day.ToString(); l.Cursor = Cursors.Hand; l.Click += new EventHandler(l_Click); if (flow.type == FlowType.income) { exist = false; foreach (Label l_in in flowLayoutPanel_in.Controls) { if (l_in.Text == l.Text) exist = true; } if (!exist) flowLayoutPanel_in.Controls.Add(l); } else if (flow.type == FlowType.payout) { exist = false; foreach (Label l_out in flowLayoutPanel_out.Controls) { if (l_out.Text == l.Text) exist = true; } if (!exist) flowLayoutPanel_out.Controls.Add(l); } else { } } } } }