public static bool WriteNewVersion(VersionOBJ verObj, string sfilePath) { bool result; result = true; try { string s; s = verObj.VersionID + "\r\n"; s += verObj.VersionName + "\r\n"; s += verObj.FileName + "\r\n"; s += verObj.Date; StreamWriter sw = new StreamWriter(sfilePath); sw.WriteLine(s); sw.Close(); } catch (Exception ex) { result = false; } return(result); }
public bool CheckNewVersion() { bool result; //result = true; VersionOBJ verObj = VersionCTL.GetLastestVersion(); if (verObj.VersionID == string.Empty) { return(false); } string sPath = Path.GetDirectoryName(Application.ExecutablePath); string sfilePath = sPath + "\\version.dat"; string sCurVersionID = VersionCTL.ReadCurrentVersion(sfilePath); if (sCurVersionID == string.Empty || verObj.VersionID != sCurVersionID) { result = true; } else { result = false; } return(result); }
public static bool InsertNewVersion(VersionOBJ verObj) { bool result; result = true; try { string sSql = "INSERT INTO Version(VersionID, VersionName, VersionType, FileName, FileSize, Date, Notes) VALUES(@VersionID, @VersionName, @VersionType, @FileName, @FileSize, GETDATE(), @Notes)"; SqlCommand cmd = new SqlCommand(sSql); cmd.Parameters.Add("@VersionID", SqlDbType.VarChar).Value = verObj.VersionID; cmd.Parameters.Add("@VersionName", SqlDbType.VarChar).Value = verObj.VersionName; cmd.Parameters.Add("@VersionType", SqlDbType.VarChar).Value = verObj.VersionType; cmd.Parameters.Add("@FileName", SqlDbType.VarChar).Value = verObj.FileName; cmd.Parameters.Add("@FileSize", SqlDbType.Int).Value = verObj.FileSize; cmd.Parameters.Add("@Notes", SqlDbType.VarChar).Value = verObj.Notes; result = DataProvider.ExecuteQuery(cmd); } catch (Exception ex) { result = false; } return(result); }
public bool DownloadTheLastestVersion() { bool result = true; UpdateStatusProgressBar(0, "Chuẩn bị dữ liệu..."); //Step 0: Prepare data string sPath = Path.GetDirectoryName(Application.ExecutablePath); UpdateStatusProgressBar(10, "Đang lấy thông tin phiên bản mới..."); //Step 1: Get the lastest version VersionOBJ verObj = VersionCTL.GetLastestVersion(); if (verObj.VersionID == string.Empty) { MessageBox.Show("Lỗi! Không thể cập nhật phiên bản mới!"); return(false); } string szipFilePath = sPath + "\\CRM_ver_" + verObj.VersionID + ".zip"; UpdateStatusProgressBar(45, "Đang tải tập tin..."); //Step 2: Download zip file from server and save in the Path if (SegmentDataCTL.DownloadFileFromServer(verObj.VersionID, szipFilePath) == false) { MessageBox.Show("Lỗi! Không thể tải tập tin!"); return(false); } UpdateStatusProgressBar(20, "Đang cập nhật phiên bản mới..."); //Step 3: Extract zip file try { string sOutputPath = sPath; ZipArchiveMOD.UnzipFile(szipFilePath, sOutputPath); } catch (Exception ex) { MessageBox.Show("Lỗi! Không thể giải nVN tập tin! Chi tiết: " + ex.Message); return(false); } UpdateStatusProgressBar(0, "Hoàn tất"); //Step 4: Write a new version to file string sfileVerPath = sPath + "\\version.dat"; VersionCTL.WriteNewVersion(verObj, sfileVerPath); File.Delete(szipFilePath); MessageBox.Show("Cập nhật phiên bản mới thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
public void DownloadTheLastestVersion() { UpdateStatusProgressBar(0, "Preparing data..."); //Step 0: Prepare data string sPath = Path.GetDirectoryName(Application.ExecutablePath); UpdateStatusProgressBar(10, "Getting lastest version..."); //Step 1: Get the lastest version VersionOBJ verObj = VersionCTL.GetLastestVersion(); if (verObj.VersionID == string.Empty) { MessageBox.Show("Error! Can't get new version!"); return; } //string szipFilePath = sPath + "\\" + verObj.FileName; string szipFilePath = sPath + "\\CRM_Download.zip"; UpdateStatusProgressBar(45, "Downloading file..."); //Step 2: Download zip file from server and save in the Path if (SegmentDataCTL.DownloadFileFromServer(verObj.VersionID, szipFilePath) == false) { MessageBox.Show("Error! Can't download upload file!"); return; } UpdateStatusProgressBar(20, "Updating file..."); //Step 3: Extract zip file try { string sOutputPath = sPath + "\\tmp1"; ZipArchiveMOD.UnzipFile(szipFilePath, sOutputPath); } catch { MessageBox.Show("Error! Can't extract zip file!"); return; } UpdateStatusProgressBar(0, "Finished"); MessageBox.Show("Download file successfully!"); //Step 4: Copy and overwrite (maybe) to folder QuanLyDiem btn_Upload.Enabled = true; btn_Download.Enabled = true; }
public void CreateNewVersion() { int ID; VersionOBJ verObj = VersionCTL.GetLastestVersion(); if (verObj.VersionID == string.Empty) { ID = 1; } else { ID = int.Parse(verObj.VersionID) + 1; } txt_VersionID.Text = ID.ToString(); txt_VersionName.Text = "CRM-ver" + ID.ToString(); txt_FileName.Text = "CRM.zip"; }
public static VersionOBJ GetLastestVersion() { VersionOBJ verObj = new VersionOBJ(); List <VersionOBJ> lst = GetAllVersions(); if (lst != null) { verObj.VersionID = lst[lst.Count - 1].VersionID; verObj.VersionName = lst[lst.Count - 1].VersionName; verObj.VersionType = lst[lst.Count - 1].VersionType; verObj.FileName = lst[lst.Count - 1].FileName; verObj.FileSize = lst[lst.Count - 1].FileSize; verObj.Date = lst[lst.Count - 1].Date; verObj.Notes = lst[lst.Count - 1].Notes; } return(verObj); }
public static List <VersionOBJ> GetAllVersions() { List <VersionOBJ> lst = new List <VersionOBJ>(); try { DataTable dt = new DataTable(); string sSql = "SELECT * FROM Version ORDER BY VersionID ASC"; dt = DataProvider.GetData(sSql); if (dt.Rows.Count > 0) { VersionOBJ verObj = new VersionOBJ(); verObj.VersionID = dt.Rows[dt.Rows.Count - 1]["VersionID"].ToString(); verObj.VersionName = dt.Rows[dt.Rows.Count - 1]["VersionName"].ToString(); verObj.VersionType = dt.Rows[dt.Rows.Count - 1]["VersionType"].ToString(); verObj.FileName = dt.Rows[dt.Rows.Count - 1]["FileName"].ToString(); verObj.FileSize = long.Parse(dt.Rows[dt.Rows.Count - 1]["FileSize"].ToString()); verObj.Date = dt.Rows[dt.Rows.Count - 1]["Date"].ToString(); verObj.Notes = dt.Rows[dt.Rows.Count - 1]["Notes"].ToString(); lst.Add(verObj); } else { lst = null; } } catch (Exception ex) { lst = null; } return(lst); }
public static bool WriteNewVersion(VersionOBJ verObj, string sfilePath) { return(VersionMOD.WriteNewVersion(verObj, sfilePath)); }
public static bool InsertNewVersion(VersionOBJ verObj) { return(VersionMOD.InsertNewVersion(verObj)); }
private void btn_GetLastestVersion_Click(object sender, EventArgs e) { VersionOBJ verObj = VersionCTL.GetLastestVersion(); MessageBox.Show("VersionID: " + verObj.VersionID + " - VersionName: " + verObj.VersionName + " - FileName: " + verObj.FileName); }
public void UploadNewVersion() { DateTime startDT = DateTime.Now; try { UpdateStatusProgressBar(0, "Preparing data..."); //Step 0: Prepare data string sPath = Path.GetDirectoryName(Application.ExecutablePath); string szipFilePath = sPath + "\\" + txt_FileName.Text; UpdateStatusProgressBar(0, "Creating new zip file..."); //Step 1: Create new zip file (includes list of update files) try { string sUpdateFolder = sPath; ZipArchiveMOD.CreateArchive(szipFilePath, sUpdateFolder, this.lstUploadFiles, true); } catch (Exception ex1) { MessageBox.Show("Error! Create zip file: " + ex1.Message); btn_Upload.Enabled = true; btn_Download.Enabled = true; return; } UpdateStatusProgressBar(45, "Inserting version..."); //Step 2: Insert version VersionOBJ verObj = new VersionOBJ(); verObj.VersionID = txt_VersionID.Text; verObj.VersionName = txt_VersionName.Text; verObj.FileName = txt_FileName.Text; //FileInfo fi = new FileInfo(szipFilePath); //verObj.FileSize = fi.Length; verObj.FileSize = (new FileInfo(szipFilePath)).Length; verObj.VersionType = "TH-CRM"; verObj.Notes = txt_Notes.Text; UpdateStatusProgressBar(0, "Inserting version..."); if (VersionCTL.InsertNewVersion(verObj) == false) { MessageBox.Show("Error! Insert Version"); btn_Upload.Enabled = true; btn_Download.Enabled = true; return; } UpdateStatusProgressBar(0, "Uploading file to server..."); //Step 3: Upload file to server if (SegmentDataCTL.UploadFileToServer(szipFilePath, verObj.VersionID, verObj.Notes)) { DateTime endDT = DateTime.Now; //DateTime delta = endDT - startDT; long totalSecond = 0; if (endDT.Second > startDT.Second) { totalSecond = (endDT.Hour - startDT.Hour) * 60 * 60 + (endDT.Minute - startDT.Minute) * 60 + (endDT.Second - startDT.Second); } else { totalSecond = (endDT.Hour - startDT.Hour) * 60 * 60 + (endDT.Minute - startDT.Minute - 1) * 60 + (endDT.Second + 60 - startDT.Second); } UpdateStatusProgressBar(25, "Finished"); MessageBox.Show("Files uploaded successfully! Total second: " + totalSecond.ToString()); } else { MessageBox.Show("Error! Upload file!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } btn_Upload.Enabled = true; btn_Download.Enabled = true; //thread.Abort(); }