private void LoginAction() { ApiResponse res = new ApiResponse(); try { string url = "auth/token"; var paras = "{\"email\": \"" + txtUserId.Text.Trim() + "\",\"password\": \"" + txtPass.Text.Trim() + "\",\"rememberMe\": " + "true" + " }"; res = HTTP.PostJson(url, paras); if (res.Status && Util.IsJson(res.RawText)) { TokenObject _TokenObject = JsonConvert.DeserializeObject <TokenObject>(res.RawText, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); ERP.Base.Config.Token = "Bearer " + _TokenObject.id_token; Main frmMain = new Main(); frmMain.Show(); this.Hide(); frmMain.frmLogin = this; } else { ERP.Base.Config.Token = null; MessageBox.Show("Failed to sign in! Please check your credentials and try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { ERP.Base.Config.Token = null; MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } }
private void btnSave_Click(object sender, EventArgs e) { if (this.dtList.Rows.Count > 0) { ApiResponse res = new ApiResponse(); res.Status = false; try { string url = "smart-devices/update-locations"; string param = "["; foreach (DataRow row in dtList.Rows) { param += "{"; if (BarcodeLocation != null && BarcodeLocation.Length > 0) { param += "\"locationCode\": \"" + BarcodeLocation + "\", "; } if (Util.getTypePackage(row[COL_ID].ToString().Trim(), row[COL_TYPE].ToString()) % 2 == 0) { param += "\"lotNumber\": \"" + row[COL_ID] + "\""; } else { param += "\"packageNumber\": \"" + row[COL_ID] + "\""; } param += "}, "; } string end_char = param.Substring(param.Length - 2, 1); if (end_char == ",") { param = param.Substring(0, param.Length - 2); } param += " ]"; param = param.Replace(System.Environment.NewLine, "").Trim(); //Util.Logs(param); res = HTTP.PostJson(url, param); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); //MessageBox.Show(ex.InnerException.ToString()); } if (res.Status) { try { List <LocationUpdate> RootObject = JsonConvert.DeserializeObject <List <LocationUpdate> >(res.RawText, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); List <LocationUpdate> ListDetail = RootObject as List <LocationUpdate>; //dtList.Rows.Clear(); foreach (LocationUpdate item in ListDetail) { string packIdResponse = item.lotNumber != null && item.lotNumber.Length > 0 ? item.lotNumber : item.packageNumber; DataRow[] rs_package = dtList.Select(COL_ID + " = '" + packIdResponse.Trim() + "'"); if (rs_package.Length > 0) { rs_package[0][COL_STATUS] = item.errorCode != null && item.errorCode.Length > 0 ? "error" : ""; rs_package[0][COL_ERROR_CODE] = item.errorCode != null && item.errorCode.Length > 0 ? item.errorCode : ""; } } this.dtList.DefaultView.Sort = COL_STATUS + " DESC"; this.dtList = this.dtList.DefaultView.ToTable(); this.dgCuonList.DataSource = this.dtList; this.dgCuonList.Refresh(); } catch { } MessageBox.Show("Update location done !"); } else { //MessageBox.Show(res.RawText); } btnSave.Enabled = false; btnClear.Enabled = true; } else { MessageBox.Show("Request scanned package before saving !"); } }
private void btnSave_Click(object sender, EventArgs e) { LocationInfo locationInfo = LocationBusiness.getInfo(_LocationInfo.id); if (locationInfo == null) { MessageBox.Show("Location is not exists in inventory!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } //_action = "save"; string param = ""; try { _Adjustment.adjustmentDetails = this._ListSpace;//Util.DataTableToList<AdjustmentDetail>(this.dtList); param = JsonConvert.SerializeObject(_Adjustment); param = param.Replace(System.Environment.NewLine, "").Trim(); } catch (Exception ex) { MessageBox.Show("Client error: " + ex.ToString()); return; } ApiResponse res = new ApiResponse(); res.Status = false; string url = "inventories/gen-details"; //string url = "inventories/" + this.Adjustment.id.ToString(); //Util.Logs(param); try { //res = HTTP.Put(url, param); res = HTTP.PostJson(url, param); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } if (res.Status) { try { Adjustment RootObject = JsonConvert.DeserializeObject <Adjustment>(res.RawText, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); Adjustment AdjustmentResponse = RootObject as Adjustment; List <AdjustmentDetail> ListError = AdjustmentResponse.errorDetails; foreach (AdjustmentDetail item in ListError) { if (item.id != null) { DataRow[] rs_package = dtList.Select("id" + " = " + item.id.ToString()); if (rs_package.Length > 0) { rs_package[0][COL_STATUS] = "error"; } } else { DataRow[] rs_package; if (item.packageNumber != null && item.traceNumber != null) { rs_package = dtList.Select(COL_PACK + " = '" + item.packageNumber + "' AND " + COL_LOT + " = '" + item.traceNumber + "'"); } else if (item.packageNumber != null) { rs_package = dtList.Select(COL_PACK + " = '" + item.packageNumber + "'"); } else //if (item.traceNumber != null) { rs_package = dtList.Select(COL_LOT + " = '" + item.traceNumber + "'"); } if (rs_package.Length > 0) { rs_package[0][COL_STATUS] = "error"; } } } this.dtList.DefaultView.Sort = COL_STATUS + " DESC"; this.dtList = this.dtList.DefaultView.ToTable(); this.dgCuonList.DataSource = this.dtList; this.dgCuonList.Refresh(); } catch (Exception ex) { MessageBox.Show("View error: " + ex.Message.ToString()); } MessageBox.Show("Success !"); btnSave.Enabled = false; //btnClear.Enabled = false; //this.dtList.Rows.Clear(); //this.dgCuonList.Refresh(); //this._ListSpace.Clear(); this.locationBarcode = null; //this.lblLocationBarcode.Text = null; } else { //Util.Logs("res.Message: " + res.Message + " --- res.RawText: " + res.RawText); } }
private void btnSave_Click(object sender, EventArgs e) { if (this.dtList.Rows.Count > 0) { ApiResponse res = new ApiResponse(); res.Status = false; try { string url = "smart-devices/move-packages"; string param = "{ \"destPackageNumber\": \"" + DestPackageNumber.Trim() + "\", \"lotNumbers\": ["; foreach (DataRow row in dtList.Rows) { param += "\"" + row[COL_LOT_ID] + "\","; } param = param.Replace(System.Environment.NewLine, "").Trim(); param = param.Substring(0, param.Length - 1); //string end_char = param.Substring(param.Length - 2, 1); //while (end_char != ",") //{ // param = param.Substring(0, param.Length - 2); // end_char = param.Substring(param.Length - 2, 1); //} //if (end_char == ",") param = param.Substring(0, param.Length - 2); if (dtList.Rows[0][COL_PACK_ID] != null && dtList.Rows[0][COL_PACK_ID].ToString().Trim().Length > 0) { param += "], \"srcPackageNumber\": \"" + dtList.Rows[0][COL_PACK_ID] + "\" }"; } else { param += "], \"srcPackageNumber\": null }"; } param = param.Replace(System.Environment.NewLine, "").Trim(); res = HTTP.PostJson(url, param); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); //MessageBox.Show(ex.InnerException.ToString()); } if (res.Status) { try { PackagingResponse RootObject = JsonConvert.DeserializeObject <PackagingResponse>(res.RawText, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); PackagingResponse Response = RootObject as PackagingResponse; if (Response.invalidLotNumbers.Count > 0) { string message = "Error occurred with unit ID: "; foreach (string item in Response.invalidLotNumbers) { message += item + ","; } string end_char = message.Substring(message.Length - 1, 1); if (end_char == ",") { message = message.Substring(0, message.Length - 1); } MessageBox.Show(message); } else { MessageBox.Show("Move unit ID to package successfully!"); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } else { //MessageBox.Show(res.RawText); } //btnSave.Enabled = false; //btnClear.Enabled = true; } else { MessageBox.Show("Request scanned package before saving !"); } }