Exemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         DataSet temp = new DataSet();
         temp.Tables.Add(DgvToDt());
         FormSaveas f = new FormSaveas();
         f.ShowDialog();
         if (Saveas != "!!!")
         {
             file = Saveas;
             temp.WriteXml(file);
             Z.Clear();
             for (int i = 0; i < dataGridView1.RowCount; ++i)
             {
                 for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; ++j)
                 {
                     if (dataGridView1.Rows[i].Cells[j].Value == null)
                     {
                         Z.Add("");
                     }
                     else
                     {
                         Z.Add(dataGridView1.Rows[i].Cells[j].Value.ToString());
                     }
                 }
             }
         }
     }
     catch (Exception) { MessageBox.Show("Invalid Name", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
 }
Exemplo n.º 2
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Saveas = "";
            DataSet temp = new DataSet();

            temp.Tables.Add(DgvToDt());
            FormSaveas f = new FormSaveas();

            if (file == "C:\\Help\\New File.xml")
            {
                if (Saveas != "!!!")
                {
                    f.ShowDialog();
                    file = Saveas;
                    temp.WriteXml(file);
                }
                else
                {
                    temp.WriteXml("C:\\Test\\8.xml");
                }
            }
            if (Saveas != "!!!")
            {
                Z.Clear();
                temp.WriteXml(file);
                for (int i = 0; i < dataGridView1.RowCount; ++i)
                {
                    for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; ++j)
                    {
                        if (dataGridView1.Rows[i].Cells[j].Value == null)
                        {
                            Z.Add("");
                        }
                        else
                        {
                            Z.Add(dataGridView1.Rows[i].Cells[j].Value.ToString());
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void FormTable_FormClosing(object sender, FormClosingEventArgs e)
        {
            DataSet temp = new DataSet();

            temp.Tables.Add(DgvToDt());
            List <string> N = new List <string>();

            for (int i = 0; i < dataGridView1.RowCount; ++i)
            {
                for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; ++j)
                {
                    if (dataGridView1.Rows[i].Cells[j].Value == null)
                    {
                        N.Add("");
                    }
                    else
                    {
                        N.Add(dataGridView1.Rows[i].Cells[j].Value.ToString());
                    }
                }
            }
            bool flag = true;

            if (N.Count == Z.Count)
            {
                for (int i = 0; i < N.Count; ++i)
                {
                    if (Z[i] != N[i])
                    {
                        flag = false;
                    }
                    else
                    {
                        ;
                    }
                }
            }
            else
            {
                flag = false;
            }
            if (!flag)
            {
                if (DialogResult.Yes == (DialogResult)MessageBox.Show("File is not saved. Save?", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    if (file != "C:\\Help\\New File.xml")
                    {
                        temp.WriteXml(file);
                    }
                    else
                    {
                        FormSaveas f = new FormSaveas();
                        f.ShowDialog();
                        if (Saveas != "!!!")
                        {
                            file = Saveas;
                            temp.WriteXml(file);
                        }
                    }
                }
            }
        }