private void DoUpdate()
        {
            #region Do Update
            try
            {
                DataTable dt = new DataTable();

                using (SqlConnection cnn = Class.datatabase.getConnection())
                {
                    cnn.Open();

                    SqlDataAdapter adap = new SqlDataAdapter(@"SELECT TOP 1 * FROM Software_Update ORDER BY SoftwareId DESC", cnn);

                    adap.Fill(dt);

                    if (dt.Rows.Count > 0)
                    {
                        if (dt.Rows[0]["NewVersion"].ToString() != textBoxCurentVersion.Text)
                        {
                            frmMessUpdateSW frm = new frmMessUpdateSW();
                            frm.NameVersion    = dt.Rows[0]["SWName"].ToString();
                            frm.OldVerSion     = textBoxCurentVersion.Text;
                            frm.NewVersion     = dt.Rows[0]["NewVersion"].ToString();
                            frm.ChangeLogs     = dt.Rows[0]["ChangeLogs"].ToString();
                            frm.UpdateLocation = dt.Rows[0]["UpdateLocation"].ToString();
                            frm.FileSize       = dt.Rows[0]["FileSize"].ToString();
                            frm.md5            = dt.Rows[0]["md5"].ToString();

                            Uri    location = new Uri(dt.Rows[0]["UpdateLocation"].ToString());
                            string fileName = dt.Rows[0]["SWName"].ToString();
                            idsoftware = dt.Rows[0]["SoftwareId"].ToString();

                            if (frm.ShowDialog() == DialogResult.OK)
                            {
                                frmUpdateDownload form   = new frmUpdateDownload(location, fileName, idsoftware, textBoxCurentVersion.Text, dt.Rows[0]["NewVersion"].ToString());
                                DialogResult      result = form.ShowDialog();

                                if (result == DialogResult.OK)
                                {
                                    dt.Dispose();
                                    cnn.Close();
                                }
                                else if (result == DialogResult.Abort)
                                {
                                    MessageBox.Show("Tải về bản cập nhật đã bị hủy bỏ!\nChương trình chưa được cập nhật!", "Hủy bỏ tải về cập nhật", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show("Đã xảy ra vấn đề trong lúc tải về bản cập nhật!\nVui lòng thử lại sau!", "Lỗi tải về bản cập nhật", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Bạn đang dùng phiên bản mới nhất của phần mềm Autocare");
                        }
                    }
                    cnn.Close();
                }
            }
            catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message + "\nVui lòng kiểm tra lại đường truyền Internet!"); }
            #endregion
        }
예제 #2
0
        private void bgAutoUpdate_DoWork(object sender, DoWorkEventArgs e)
        {
            TimeSpan interval = new TimeSpan(0, 0, 10);

            Thread.Sleep(interval);
            Microsoft.Win32.RegistryKey ReadKey;
            ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareUpdate");
            if (ReadKey == null)
            {
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("AutoCareUpdate");
                key.SetValue("AutoUpdate", true);
                key.Close();
            }

            bool AutoUpdate = false;

            try
            {
                AutoUpdate = bool.Parse(ReadKey.GetValue("AutoUpdate").ToString());
            }
            catch (Exception) { }

            if (AutoUpdate == true)
            {
                try
                {
                    DataTable dt = new DataTable();

                    using (SqlConnection cnn = Class.datatabase.getConnection())
                    {
                        cnn.Open();

                        SqlDataAdapter adap = new SqlDataAdapter(@"SELECT TOP 1 * FROM Software_Update ORDER BY SoftwareId DESC", cnn);

                        adap.Fill(dt);

                        if (dt.Rows.Count > 0)
                        {
                            if (dt.Rows[0][3].ToString() != oldversion)
                            {
                                frmMessUpdateSW frm = new frmMessUpdateSW();
                                frm.NameVersion    = dt.Rows[0][1].ToString();
                                frm.OldVerSion     = oldversion;
                                frm.NewVersion     = dt.Rows[0][3].ToString();
                                frm.ChangeLogs     = dt.Rows[0][4].ToString();
                                frm.UpdateLocation = dt.Rows[0][5].ToString();
                                frm.FileSize       = dt.Rows[0][6].ToString();
                                frm.md5            = dt.Rows[0][7].ToString();

                                Uri    location   = new Uri(dt.Rows[0][5].ToString());
                                string fileName   = dt.Rows[0][1].ToString();
                                string idsoftware = dt.Rows[0][0].ToString();
                                string NewVersion = dt.Rows[0][3].ToString();

                                if (frm.ShowDialog() == DialogResult.OK)
                                {
                                    frmUpdateDownload form   = new frmUpdateDownload(location, fileName, idsoftware, oldversion, NewVersion);
                                    DialogResult      result = form.ShowDialog();

                                    if (result == DialogResult.OK)
                                    {
                                        dt.Dispose();
                                    }
                                    else if (result == DialogResult.Abort)
                                    {
                                        MessageBox.Show("Tải về bản cập nhật đã bị hủy bỏ!\nChương trình chưa được cập nhật!", "Hủy bỏ tải về cập nhật", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        dt.Dispose();
                                    }
                                    else
                                    {
                                        MessageBox.Show(" Đã xảy ra vấn đề trong lúc tải về bản cập nhật!\nVui lòng thử lại sau!", "Lỗi tải về bản cập nhật", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        dt.Dispose();
                                    }
                                }
                            }
                        }
                        cnn.Close();
                    }
                }
                catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message + "\nVui lòng kiểm tra lại đường truyền mạng!"); }
            }
        }