예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            int m = dateTimePicker2.Value.Month;
            int y = dateTimePicker2.Value.Year;
            bool flag = false;

            if (y == DateTime.Now.Year)
            {
                if (m > DateTime.Now.Month)
                    flag = true;
            }
            else if (y > DateTime.Now.Year)
                flag = true;

            if (flag)
            {
                decimal[] amt = { 0, 0, 0, 0, 0, 0, 0, 0 };

                Decimal.TryParse(textBox1.Text, out amt[0]);
                Decimal.TryParse(textBox2.Text, out amt[1]);
                Decimal.TryParse(textBox3.Text, out amt[2]);
                Decimal.TryParse(textBox4.Text, out amt[3]);
                Decimal.TryParse(textBox5.Text, out amt[4]);
                Decimal.TryParse(textBox6.Text, out amt[5]);
                Decimal.TryParse(textBox7.Text, out amt[6]);
                Decimal.TryParse(textBox8.Text, out amt[7]);

                Category[] temp = (from x in db.Categories orderby x.Name ascending select x).ToArray();

                for (int i = 0; i < 8; i++)
                {
                    Plan p = new Plan();
                    p.Amount = amt[i];
                    p.Category = temp[i].Name;
                    p.Month = m;
                    p.Year = y;

                    db.Plans.InsertOnSubmit(p);
                    db.SubmitChanges();
                }
                textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = textBox5.Text = textBox6.Text
                    = textBox7.Text = textBox8.Text = "";
                dateTimePicker2.Value = DateTime.Now;
                refreshData();
                MessageBox.Show(this, "New Plan submitted, any empty Category is submitted as 0 (zero)", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(this, "Plan Month/Year must be greater than current Month/Year", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
 partial void DeletePlan(Plan instance);
 partial void UpdatePlan(Plan instance);
 partial void InsertPlan(Plan instance);
예제 #5
0
        private void plansToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Utility.mySettings.DefaultFileLocation;
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            {
                string filePath = openFileDialog1.FileName;
                long rows = Utility.CountLinesInFile(filePath);
                if (rows > 0)
                {
                    toolStripProgressBar1.Visible = true;
                    toolStripProgressBar1.Maximum = (int)rows;
                    toolStripProgressBar1.Value = 0;
                }
                StreamReader sr = new StreamReader(filePath);
                int x = 0;
                while (!sr.EndOfStream)
                {
                    string[] Line = sr.ReadLine().Split(',');

                    try
                    {
                        Plan o = new Plan();
                        o.Month = Int32.Parse(Line[1].Trim());
                        o.Year = Int32.Parse(Line[2].Trim());
                        o.Amount = Decimal.Parse(Line[3].Trim());
                        o.Category = convertCategory(Line[4].Trim());

                        db.Plans.InsertOnSubmit(o);
                        db.SubmitChanges();
                        x++;
                        if (rows > 0)
                            toolStripProgressBar1.Value++;
                    }
                    catch (Exception ex)
                    {

                    }
                }
                sr.Close();

                MessageBox.Show(this, x + " rows of Plan imported", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                toolStripProgressBar1.Visible = false;
            }
        }