private bool ImportData(StmasImportVM stmas, bool update_existing) { ApiAccessibilities acc = new ApiAccessibilities { API_KEY = this.main_form.config.ApiKey, USER_ID = this.main_form.logedin_user.Id, stmas_import = stmas }; APIResult post; if (update_existing == false) // add mode { post = APIClient.POST(this.main_form.config.ApiUrl + "Stmas/ImportAdd", acc); } else // edit mode { post = APIClient.POST(this.main_form.config.ApiUrl + "Stmas/ImportUpdate", acc); } if (post.Success) { return(true); } else { if (MessageBox.Show(post.ErrorMessage, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { return(this.ImportData(stmas, update_existing)); } return(false); } }
private void ImportDowork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; var i = 0; foreach (var stmas in this.stmasvm) { i++; if (worker.CancellationPending) { e.Cancel = true; return; } else { StmasImportVM st_exist = null; APIResult get = APIClient.GET(this.main_form.config.ApiUrl + "Stmas/GetImportModelForCheckExist", this.main_form.config.ApiKey, "&stkcod=" + stmas.Stkcod.Trim()); if (get.Success) { st_exist = JsonConvert.DeserializeObject <StmasImportVM>(get.ReturnValue); } if (st_exist != null) // is exist importing stkcod { StmasImportDuplicateAlertDialog alert = new StmasImportDuplicateAlertDialog(st_exist.Stkcod.Trim()); if (alert.ShowDialog() == DialogResult.OK) // replace with new data (Update) { stmas.Id = st_exist.Id; if (this.ImportData(stmas, true)) { worker.ReportProgress(i); } else { worker.CancelAsync(); } } else // skip duplicate data { worker.ReportProgress(i); } } else // is not exist { if (this.ImportData(stmas, false)) { worker.ReportProgress(i); } else { worker.CancelAsync(); } } } } }
public static StmasImportVM ToViewModel(this Stmas stmas, List <Istab> stkgrp_list, List <Istab> qucod_list) { if (stmas == null) { return(null); } var grp = stkgrp_list.Where(i => i.typcod.Trim() == stmas.stkgrp.Trim()).FirstOrDefault(); var stkgrp = new IstabVM { TabTyp = ((int)ISTAB_TABTYP.STKGRP).ToString(), TypCod = stmas.stkgrp.Trim() }; if (grp != null) { stkgrp.AbbreviateTh = grp.shortnam.Trim(); stkgrp.AbbreviateEn = grp.shortnam2.Trim(); stkgrp.TypDesTh = grp.typdes.Trim(); stkgrp.TypDesEn = grp.typdes2.Trim(); } else { stkgrp.AbbreviateTh = ""; stkgrp.AbbreviateEn = ""; stkgrp.TypDesTh = ""; stkgrp.TypDesEn = ""; } var qu = qucod_list.Where(i => i.typcod.Trim() == stmas.qucod.Trim()).FirstOrDefault(); var qucod = new IstabVM { TabTyp = ((int)ISTAB_TABTYP.QUCOD).ToString(), TypCod = stmas.qucod.Trim() }; if (qu != null) { qucod.AbbreviateTh = qu.shortnam.Trim(); qucod.AbbreviateEn = qu.shortnam2.Trim(); qucod.TypDesTh = qu.typdes.Trim(); qucod.TypDesEn = qu.typdes2.Trim(); } else { qucod.AbbreviateTh = ""; qucod.AbbreviateEn = ""; qucod.TypDesTh = ""; qucod.TypDesEn = ""; } StmasImportVM st = new StmasImportVM { Stkcod = stmas.stkcod, StkDesTh = stmas.stkdes, StkDesEn = stmas.stkdes2, Barcod = stmas.barcod, StkTyp = stmas.stktyp, //StkGrp = stmas.StkGrp, //Qucod = stmas.Qucod, Sellpr1 = (decimal)stmas.sellpr1, Sellpr2 = (decimal)stmas.sellpr2, Sellpr3 = (decimal)stmas.sellpr3, Sellpr4 = (decimal)stmas.sellpr4, Sellpr5 = (decimal)stmas.sellpr5, //ProductImg = stmas.ProductImg, _StkGrp = stkgrp, _QuCod = qucod }; return(st); }