Esempio n. 1
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            DialogResult tl = MessageBox.Show("Delete and close?", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (tl == DialogResult.Cancel)
            {
                return;
            }

            ItemHelper itemHel = new ItemHelper();

            itemHel.deleteItem(tempItem);


            this.Close();
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtDec.Text))
            {
                MessageBox.Show("Please fill in description box");
                return;
            }



            DialogResult tl = MessageBox.Show("Save and close?", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (tl == DialogResult.Cancel)
            {
                return;
            }


            if (tempItem != null)
            {
                tempItem.dateTime   = dateTimePicker1.Text.ToString() + " " + dateTimePicker2.Text.ToString();
                tempItem.decription = txtDec.Text.Trim();
                if (comboBox1.Visible)
                {
                    if (!comboBox1.SelectedValue.Equals("Choose a program"))
                    {
                        tempItem.program = comboBox1.SelectedValue.ToString();
                    }
                    else
                    {
                        if (!link.Equals(""))
                        {
                            tempItem.program = link;
                        }
                        else
                        {
                            tempItem.program = "-1";
                        }
                    }
                }
                else
                {
                    tempItem.program = "-1";
                }

                ItemHelper itemHel = new ItemHelper();
                itemHel.replaceItem(tempItem);
            }
            else
            {
                // Lấy index và ghi index lại
                int      index = 0;
                string[] lines = File.ReadAllLines("data/inf.inf");
                if (lines.Count() > 0)
                {
                    index = Convert.ToInt32(lines[0]);
                }
                index++;


                String       filepath = "data/data.inf";
                FileStream   fs       = new FileStream(filepath, FileMode.Append);
                StreamWriter sWriter  = new StreamWriter(fs, Encoding.UTF8);//fs là 1 FileStream
                sWriter.WriteLine(index.ToString());
                sWriter.WriteLine(dateTimePicker1.Text.ToString() + " " + dateTimePicker2.Text.ToString());
                sWriter.WriteLine(txtDec.Text.ToString().Trim());
                if (comboBox1.Visible)
                {
                    if (!comboBox1.SelectedValue.Equals("Choose a program"))
                    {
                        sWriter.WriteLine(comboBox1.SelectedValue);
                    }
                    else
                    {
                        if (!link.Equals(""))
                        {
                            sWriter.WriteLine(link);
                        }
                        else
                        {
                            sWriter.WriteLine(-1);
                        }
                    }
                }
                else
                {
                    sWriter.WriteLine(-1);
                }


                sWriter.Flush();
                fs.Close();


                filepath = "data/inf.inf";
                fs       = new FileStream(filepath, FileMode.Create);
                sWriter  = new StreamWriter(fs, Encoding.UTF8);
                sWriter.WriteLine(index.ToString());
                sWriter.Flush();
                fs.Close();



                ItemHelper itemHelper = new ItemHelper();
                itemHelper.Sort();
            }
            this.Close();
        }