private void bwDefault_DoWork(object sender, DoWorkEventArgs e) { #region Variable var clsTempData=new clsTempData(); var clsInvoker = new clsInvoker(); var dt = new DataTable(); var doeFrom = ""; var doeTo = ""; var registerFrom = ""; var registerTo = ""; var payor = ""; #endregion #region Procedure if (clsInvoker.getDateTimePickerChecked(dtDOEFrom)) doeFrom = clsInvoker.getDateTimePickerValue(dtDOEFrom).Value.ToString("yyyy-MM-dd HH:mm"); if (clsInvoker.getDateTimePickerChecked(dtDOETo)) doeTo = clsInvoker.getDateTimePickerValue(dtDOETo).Value.ToString("yyyy-MM-dd HH:mm"); if (clsInvoker.getDateTimePickerChecked(dtREGFrom)) registerFrom = clsInvoker.getDateTimePickerValue(dtREGFrom).Value.ToString("yyyy-MM-dd HH:mm"); if (clsInvoker.getDateTimePickerChecked(dtREGTo)) registerTo = clsInvoker.getDateTimePickerValue(dtREGTo).Value.ToString("yyyy-MM-dd HH:mm"); if (clsInvoker.getComboBox(ddlPayor)!="- ทั้งหมด -") payor = clsInvoker.getComboBox(ddlPayor); dt = clsTempData.getPatientAutoMassConvert(doeFrom, doeTo, registerFrom, registerTo, payor); if(dt!=null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { if (!bwDefault.CancellationPending) { #region ListViewUpdate clsInvoker.setListView(lvDefault, new string[] { DateTime.Now.ToString("yyyy-MM-dd HH:mm"), dt.Rows[i]["HN"].ToString(), dt.Rows[i]["Name"].ToString()+" "+dt.Rows[i]["LastName"].ToString(), dt.Rows[i]["Payor"].ToString(), dt.Rows[i]["DOE"].ToString(), dt.Rows[i]["InsuranceCompanyName"].ToString(), dt.Rows[i]["PayorAgreementName"].ToString(), dt.Rows[i]["PayorDetailName"].ToString(), dt.Rows[i]["PolicyMasterName"].ToString() }); #endregion } else { #region ListViewUpdate clsInvoker.setListView(lvDefault, new string[] { DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "", "Cancel by User", "", "", "", "", "", "" }); #endregion break; } } } else { #region ListViewUpdate clsInvoker.setListView(lvDefault, new string[] { DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "", "Don't found data for convert", "", "", "", "", "", "" }); #endregion } #endregion }
private void bwDefault_DoWork(object sender, DoWorkEventArgs e) { #region Control if (btStart.InvokeRequired) { btStart.Invoke(new MethodInvoker(delegate { btStart.Enabled = false; })); } else { btStart.Enabled = false; } if (btStop.InvokeRequired) { btStop.Invoke(new MethodInvoker(delegate { btStop.Enabled = true; })); } else { btStop.Enabled = true; } if (anLoading.InvokeRequired) { anLoading.Invoke(new MethodInvoker(delegate { anLoading.Visible = true; })); } #endregion System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); #region Variable var clsTempData = new clsTempData(); var clsSQLMain = new clsSQL(clsGlobal.dbTypeMain, clsGlobal.csMain); var clsSQLMobile = new clsSQL(clsGlobal.dbType, clsGlobal.cs); var dtMobile = new DataTable(); var dtMain = new DataTable(); var tblPatientListSTS = ""; var tblPatientStatusOnMobile = ""; var outSQL = ""; var outMessage = ""; var countSuccess = 0; var countFail = 0; var countDuplicate = 0; var clsInvoker = new clsInvoker(); var fileName = "SYNC_"+clsGlobal.ComputerName().Replace(".","")+"_"+DateTime.Now.ToString("yyyyMMddHHmmss")+".xml"; #endregion #region Procedure try { clsGlobal.AddHours = txtAddHours.Text.Trim(); countSuccess = 0; countFail = 0; countDuplicate = 0; dtMobile = clsTempData.getPatientChecklistMobile(); clsInvoker.setListView( lvDefault, Color.Green, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Start", "", "เริ่มขั้นตอนการ Sync" } ); if (dtMobile != null && dtMobile.Rows.Count > 0) { clsInvoker.setListView( lvDefault, Color.Green, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Syncing", "", "เตรียมดำเนินการสร้างไฟล์ทั้งหมด "+dtMobile.Rows.Count.ToString()+" รายการ" } ); DirectoryInfo di = new DirectoryInfo(pathSyncLocal); if (!di.Exists) { clsInvoker.setListView( lvDefault, Color.Red, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", "", "Folder's not exist. : "+di.FullName } ); di.Create(); clsInvoker.setListView( lvDefault, Color.Green, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Success", "", "สร้างโฟล์เดอร์เรียบร้อย : "+di.FullName } ); } FileInfo fi = new FileInfo(string.Format("{0}{1}", di.FullName, fileName)); if (fi.Exists) { fi.Delete(); } if (XMLCreator(dtMobile, fi.FullName)) { clsInvoker.setListView( lvDefault, Color.Green, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Success", "", "Export File Success "+dtMobile.Rows.Count.ToString()+" records. : "+fi.FullName } ); try { #region CopyToServer FileInfo fiServer = new FileInfo(string.Format("{0}{1}", pathSync, fileName)); if (fiServer.Exists) { clsInvoker.setListView( lvDefault, Color.Orange, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Exist", "", "File Exist : "+fiServer.FullName } ); try { fiServer.Delete(); clsInvoker.setListView( lvDefault, Color.Green, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Success", "", "Delete Exist" } ); } catch (Exception exDelete) { clsInvoker.setListView( lvDefault, Color.Red, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", "", "Delete Exist : "+exDelete.Message } ); } } try { clsInvoker.setListView( lvDefault, Color.Orange, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Processing...", "", "Copy file to server : "+fiServer.FullName } ); fi.CopyTo(fiServer.FullName); clsInvoker.setListView( lvDefault, Color.Green, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Success", "", "Copy file to server" } ); fi.Delete(); } catch (Exception exCopy) { clsInvoker.setListView( lvDefault, Color.Red, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", "", "Copy file to server : "+exCopy.Message } ); //fi.Delete(); } #endregion } catch(Exception exCopyFile) { clsInvoker.setListView( lvDefault, Color.Red, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", "", "Copy file to server : "+pathSync + fileName+" : "+exCopyFile.Message } ); } } else { clsInvoker.setListView( lvDefault, Color.Red, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", "", "Export File Fail. : "+fi.FullName } ); } return; //clsInvoker.setProgressBar(pbDefault, dtMobile.Rows.Count, 0); //for (int i = 0; i < dtMobile.Rows.Count; i++) //{ // if (bwDefault.CancellationPending) // { // clsInvoker.setListView( // lvDefault, // Color.Green, // 99, // new string[] { // DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Cancel", "", "Cancel by user." } // ); // e.Cancel = true; // syncTimerSecondCount = 0; // clsInvoker.setProgressBar(pbDefault, dtMobile.Rows.Count, 0); // return; // } // if (!clsSQLMain.IsConnected() || !clsSQLMobile.IsConnected()) // { // ListViewBuilder(lvDefault, Color.Red, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", "", "Cannot connect database." }); // continue; // } // #region Update tblPatientListSTS & tblPatientStatusOnMobile // if (dtMobile.Rows[i]["WFID"].ToString().Trim() == "1" && float.Parse(dtMobile.Rows[i]["ProStatus"].ToString().Trim()) >= 2) // { // tblPatientListSTS = clsSQLMain.Return("SELECT STS FROM tblPatientList WHERE PatientUID='" + dtMobile.Rows[i]["PatientGUID"].ToString().Trim() + "';"); // tblPatientStatusOnMobile = clsSQLMain.Return("SELECT StatusOnMobile FROM Patient WHERE rowguid='" + dtMobile.Rows[i]["PatientGUID"].ToString().Trim() + "';"); // if (tblPatientListSTS != "R" || tblPatientStatusOnMobile != "R") // { // if (clsSQLMain.Execute("UPDATE tblPatientList SET STS='R',SyncWhen=GETDATE() WHERE PatientUID='" + dtMobile.Rows[i]["PatientGUID"].ToString().Trim() + "';UPDATE Patient SET SyncStatus='1',SyncWhen=GETDATE(),StatusOnMobile='R' WHERE rowguid='" + dtMobile.Rows[i]["PatientGUID"].ToString().Trim() + "';")) // { // countSuccess += 1; // ListViewBuilder(lvDefault, Color.Green, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Success", dtMobile.Rows[i]["HN"].ToString(), "Update tblPatientList.STS,Patient.StatusOnMobile Complete." }); // #region UpdateSyncStatus // if (clsSQLMobile.Update( // "patient", // new string[,] // { // {"SyncStatus","'1'" }, // {"SyncWhen","SYSDATE()" } // }, // new string[,] { { } }, // "PatientGUID='" + dtMobile.Rows[i]["PatientGUID"].ToString() + "'", // out outSQL, true // )) // { // ListViewBuilder(lvDefault, Color.Green, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Success", dtMobile.Rows[i]["HN"].ToString(), "Update SyncStatus Complete." }); // } // else // { // ListViewBuilder(lvDefault, Color.Red, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", dtMobile.Rows[i]["HN"].ToString(), "Update SyncStatus Fail." }); // } // #endregion // } // else // { // countFail += 1; // ListViewBuilder(lvDefault, Color.Red, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", dtMobile.Rows[i]["HN"].ToString(), "Update tblPatientList.STS Fail." }); // } // } // } // #endregion // dtMain = clsTempData.getPatientChecklistMain(dtMobile.Rows[i]["RowID"].ToString()); // if (dtMain != null && dtMain.Rows.Count > 0) // { // if (dtMobile.Rows[i]["ProStatus"].ToString().Trim() != dtMain.Rows[0]["ProStatus"].ToString().Trim() || // dtMobile.Rows[i]["ProStatusRemark"].ToString().Trim() != dtMain.Rows[0]["ProStatusRemark"].ToString().Trim()/* || // dtMobile.Rows[i]["RegDate"].ToString().Trim() != dtMain.Rows[0]["RegDate"].ToString().Trim() || // dtMobile.Rows[i]["ModifyDate"].ToString().Trim() != dtMain.Rows[0]["ModifyDate"].ToString().Trim()*/) // { // #region Update // if (!clsSQLMain.Update( // "tblCheckList", // new string[,] // { // {"ProStatus",dtMobile.Rows[i]["ProStatus"].ToString().Trim() }, // {"ProStatusRemark","'"+dtMobile.Rows[i]["ProStatusRemark"].ToString().SQLQueryFilter()+"'" }, // {"RegDate",(dtMobile.Rows[i]["RegDate"].ToString()!=""?"'"+DateTime.Parse(dtMobile.Rows[i]["RegDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")+"'":"NULL") }, // {"ModifyDate",(dtMobile.Rows[i]["ModifyDate"].ToString()!=""?"'"+DateTime.Parse(dtMobile.Rows[i]["ModifyDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")+"'":"NULL") }, // {"SyncWhen","GETDATE()"} // }, // new string[,] { { } }, // "RowID=" + dtMobile.Rows[i]["RowID"].ToString(), out outSQL, out outMessage, true)) // { // #region LogUpdate // countFail += 1; // ListViewBuilder(lvDefault, Color.Red, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", dtMobile.Rows[i]["HN"].ToString(), dtMobile.Rows[i]["WorkFlow"].ToString() + " : " + dtMobile.Rows[i]["ProStatus"].ToString().Trim() + "->" + dtMain.Rows[0]["ProStatus"].ToString().Trim() + Environment.NewLine + outMessage }); // #endregion // } // else // { // #region LogUpdate // countSuccess += 1; // ListViewBuilder(lvDefault, Color.Green, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Success", dtMobile.Rows[i]["HN"].ToString(), dtMobile.Rows[i]["WorkFlow"].ToString() + " : " + dtMobile.Rows[i]["ProStatus"].ToString().Trim() + "->" + dtMain.Rows[0]["ProStatus"].ToString().Trim() }); // #endregion // } // #endregion // } // } // else // { // #region LogUpdate // //countDuplicate += 1; // //ListViewBuilder(lvDefault, Color.Blue, 99, // // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "NoChange", dtMobile.Rows[i]["HN"].ToString(), dtMobile.Rows[i]["WorkFlow"].ToString() + " : " + dtMobile.Rows[i]["ProStatus"].ToString().Trim() + "->" + dtMain.Rows[0]["ProStatus"].ToString().Trim() }); // #endregion // } // #region ProgressBar // if (pbDefault.InvokeRequired) // { // pbDefault.Invoke(new MethodInvoker(delegate // { // pbDefault.Value += 1; // })); // } // #endregion //} //#region ProgressBar //if (pbDefault.InvokeRequired) //{ // pbDefault.Invoke(new MethodInvoker(delegate // { // pbDefault.Visible = false; // })); //} //#endregion //#region LogUpdate //ListViewBuilder(lvDefault, Color.Green, 99, // new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Summary", "", "SyncSuccess : " + countSuccess.ToString() + " | Fail : " + countFail.ToString() + " | NoChange : " + countDuplicate.ToString() + " " }); //#endregion } else { clsInvoker.setListView( lvDefault, Color.Orange, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Warn", "", "ไม่พบข้อมูลสำหรับการ Sync" } ); } } catch (Exception exMain) { ListViewBuilder(lvDefault, Color.Red, 99, new string[] { DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Fail", "", exMain.Message }); ((Default)this.ParentForm).SyncToMainText = "SyncToMain (Syncing Fail)"; ((Default)this.ParentForm).SyncToMainTextColor = "#ED1C24"; } #endregion }