示例#1
0
        private void btnRecover_Click(object sender, EventArgs e)
        {
            //DbAndBusiness dbNew = new DbAndBusiness( txtPathNewDatabase.Text + "\\" + txtFileNewDatabase.Text);
            DataLayer    dlNew = new DataLayer(txtPathNewDatabase.Text + "\\" + txtFileNewDatabase.Text);
            List <Topic> lNew  = dlNew.GetTopics();

            if (txtFileOldDatabase.Text == "")
            {
                Console.Beep();
                return;
            }

            //DbAndBusiness dbOld = new DbAndBusiness( txtPathOldDatabase.Text + "\\" + txtFileOldDatabase.Text);
            //List<Topic> lOld = dl.GetTopics();
            DataLayer    dlOld = new DataLayer(txtPathOldDatabase.Text + "\\" + txtFileOldDatabase.Text);
            List <Topic> lOld  = dlOld.GetTopics();

            int  newIndex    = 0;
            bool newFinished = false;

            foreach (Topic tOld in lOld)
            {
                Topic tNew = lNew[newIndex];
                while (tNew.Id < tOld.Id && !newFinished)
                {
                    tNew = lNew[++newIndex];
                    if (newIndex > lNew.Count)
                    {
                        newFinished = true;
                    }
                }
                if (newFinished)
                {
                    break;
                }
                if (tOld.Id == tNew.Id)
                {
                    if (tOld.Name != tNew.Name || tOld.Desc != tNew.Desc)
                    {
                        if (chkCheckChangesSameId.Checked)
                        {
                            if (MessageBox.Show("Record diversi con lo stesso Id\r\n" +
                                                "Nuovo record = " + tNew.Id + " " + tNew.Name + " " + tNew.Desc + "\r\n" +
                                                "Vecchio record = " + tOld.Id + " " + tOld.Name + " " + tOld.Desc + "\r\n" +
                                                "Sovrascrivere il nuovo record con il vecchio?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                // ???? should we save Left Right and Parent ????"
                                dlNew.UpdateTopic(tOld, null);
                            }
                        }
                    }
                }
                else
                {
                    if (chkErasedId.Checked)
                    {
                        if (MessageBox.Show("Id non presente nel nuovo database\r\n" +
                                            "Nuovo record = " + tNew.Id + " " + tNew.Name + " " + tNew.Desc + "\r\n" +
                                            "Vecchio record = " + tOld.Id + " " + tOld.Name + " " + tOld.Desc + "\r\n" +
                                            "Aggiungere il vecchio record nel nuovo database?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            // ???? should we save Left Right and Parent ????"
                            dlNew.InsertTopic(tOld, null);
                        }
                    }
                }
            }
            this.Close();
        }