Пример #1
0
        private void btnUpdateRequiedVersion_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_VEHeader.Count <= 0)
                {
                    return;
                }
                var header = m_VEHeader[0];
                if (!header.IsVersionNull() && header.Version.Trim() == Application.ProductVersion.Trim())
                {
                    MessageBox.Show("版本号相同不需更換!");
                    return;
                }
                string ver = Application.ProductVersion.Trim();
#if UseSQLServer
                string fullDest = Path.GetFullPath(Application.ExecutablePath).ToLower();
                byte[] zipped   = null;
                byte[] md5      = null;

                if (MyFunction.CompressFileToBuf(fullDest, out zipped, out md5))
                {
                    var programAdapter = new VoucherExpense.DamaiDataSetTableAdapters.ProgramTableAdapter();
                    var cmd            = new System.Data.SqlClient.SqlCommand("DELETE FROM [dbo].[Program] WHERE 1=1");
                    cmd.Connection = programAdapter.Connection;
                    programAdapter.Connection.Open();
                    cmd.ExecuteNonQuery();
                    var table      = new VoucherExpense.DamaiDataSet.ProgramDataTable();
                    var programRow = table.NewProgramRow();
                    programRow.ID             = Guid.NewGuid();
                    programRow.ProgramVersion = ver;
                    programRow.UpdatedTime    = DateTime.Now;
                    programRow.ZippedImage    = zipped;
                    programRow.MD5            = md5;
                    table.AddProgramRow(programRow);
                    labelRequiredVersion.Text = ver + " 正在上傳";
                    Application.DoEvents();
                    programAdapter.Update(table);
                    programAdapter.Connection.Dispose();
                }
#endif
                header.Version = ver;
                VEHeaderAdapter.Update(m_VEHeader);
                labelRequiredVersion.Text = "要求版本 " + header.Version;
            }
            catch (Exception ex)
            {
                MessageBox.Show("錯誤:" + ex.Message);
            }
        }