private void ScanCode(string dcdData) { //Data test //dcdData = "PN:8NQMH3LM000001QJ*SPNK:PART-IMP-29*SDH:VNPT/TECH-BO-05/2017-112*NNK:2017-05-30*ID:0000211398*SL:50*TYPE:1*"; //dcdData = "PN:K5BXDN4M000001K3*SPNK:IMP-RE-PART-DIF-55*SDH:*NNK:15/09/2017 9:53:22 AM*ID:0000306360*SL:2000.000000*TYPE:1*"; //Obtain the string and code id. //MessageBox.Show(dcdData); try { TemCuon temCuon = new TemCuon(dcdData.Trim()); DataRow[] rs = null; if (temCuon.IdCuon != null && temCuon.IdCuon != "") { string _vnpt_pn_ok = temCuon.VnptPn; if (this._checkOther != 1 && temCuon.VnptPn.Length > 14) { _vnpt_pn_ok = _vnpt_pn_ok.Substring(0, 14); } rs = dtList.Select("vnpt_pn = '" + _vnpt_pn_ok + "'"); DataRow dr = null; if (rs.Length > 0) { dr = rs.FirstOrDefault(); } else { MessageBox.Show("Linh kien nay khong co trong danh sach xuat kho", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } //check duplicate scan PackageInfo packDuplicate = this.listScanned.SingleOrDefault(entry => entry.id_cuon == temCuon.IdCuon); if (packDuplicate != null) { MessageBox.Show("Thung/cuon da duoc quet truoc do!"); return; } if (dr != null) { double _quantity_scan = Convert.ToDouble(dr[COL_SCANNED]); double _total_export = Convert.ToDouble(dr["total_export"]); double _total_request = Convert.ToDouble(dr["total_request"]); //update table _quantity_scan += Convert.ToDouble(temCuon.SoLuong); dr[COL_SCANNED] = _quantity_scan; //add code da quet vao list PackageInfo package = new PackageInfo(); package.id_cuon = temCuon.IdCuon; package.quantity = Convert.ToDouble(temCuon.SoLuong); package.status = "DaQuet"; package.vnpt_pn = _vnpt_pn_ok; package.type = Convert.ToInt32(temCuon.Type); listScanned.Add(package); //update quantity scanned //check thung or cuon int type = Util.ConvertInt(temCuon.Type); if (type == 1) { _sl_thung_quet++; } else { _sl_cuon_quet++; } lblDaQuet.Text = _sl_thung_quet.ToString() + " thùng/" + _sl_cuon_quet.ToString() + " cuon"; //enable button save btnSave.Enabled = true; if (_quantity_scan + _total_export > _total_request) { MessageBox.Show("So luong LK da quet vuot qua so luong yeu cau xuat cua linh kien"); } } } else { MessageBox.Show("Ma thung/cuon khong dung", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { MessageBox.Show(ex.InnerException.ToString()); //MessageBox.Show("Co loi xay ra", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } }
private void btnSave_Click(object sender, EventArgs e) { string maXuatKho = txtMaXuatKho.Text.TrimStart().TrimEnd(); ApiResponse res = new ApiResponse(); res.Status = false; var listPackage = listCodeFromListObject(listScanned); try { string url = "allocateXuatKho"; if (this._checkOther == 1) { url = "allocateXuatKhoOther"; } var paras = new { ma_xuat_kho = maXuatKho, list_package = listPackage }; res = HTTP.Post(url, paras); } catch (Exception ex) { MessageBox.Show("Xay ra loi trong qua trinh allocate!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } if (res.Status && Util.IsJson(res.RawText)) { try { //Get list save fail List <string> _listFail = JsonConvert.DeserializeObject <List <string> >(res.RawText, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); if (_listFail.Count > 0) { foreach (string _id in _listFail) { PackageInfo result = this.listScanned.SingleOrDefault(s => s.id_cuon == _id); //add listSaveFail if (result != null) { result.status = "Loi"; this.listSaveFail.Add(result); } //else //{ // PackageInfo _package_fail = new PackageInfo(); // _package_fail.id_cuon = _id; // _package_fail.status = "Loi"; // _package_fail.type = 0; // this.listSaveFail.Add(_package_fail); //} } if (listScanned.Count > listSaveFail.Count) { MessageBox.Show("Da luu duoc " + (listScanned.Count - listSaveFail.Count).ToString() + " thung/cuon. Con " + listSaveFail.Count.ToString() + " thung/cuon da quet khong chinh xac!"); } else { MessageBox.Show("Allocate khong thanh cong! Thung/cuon duoc quet khong chinh xac!"); } } else { MessageBox.Show("Luu thanh cong!"); } _sl_thung_quet = 0; _sl_cuon_quet = 0; lblDaQuet.Text = _sl_thung_quet.ToString() + " thùng/" + _sl_cuon_quet.ToString() + " cuon"; btnSave.Enabled = false; } catch (Exception ex) { MessageBox.Show("Xay ra loi trong qua trinh luu!"); } } else { MessageBox.Show(res.RawText); } //Done this.listScanned.Clear(); //refresh data LoadData(maXuatKho); }
private void LoadData(string maXuatKho) { ApiResponse res = new ApiResponse(); res.Status = false; //Load danh sach linh kien try { string url = "getInfoXuatKho"; if (this._checkOther == 1) { url = "getInfoXuatKhoOther"; } var paras = new { ma_xuat_kho = maXuatKho }; res = HTTP.Post(url, paras); } catch (Exception ex) { MessageBox.Show("Loi tai du lieu xuat kho", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } if (res.Status && Util.IsJson(res.RawText)) { try { RootObject RootObject = JsonConvert.DeserializeObject <RootObject>(res.RawText, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); _sl_thung_xuat = Convert.ToInt32(Util.ReflectPropertyValue(RootObject, "sl_thung")); _sl_cuon_xuat = Convert.ToInt32(Util.ReflectPropertyValue(RootObject, "sl_cuon")); this.lblDaXuat.Text = _sl_thung_xuat.ToString() + " thùng/" + _sl_cuon_xuat.ToString() + " cuon"; object details = Util.ReflectPropertyValue(RootObject, "detail"); List <Detail> ListDetail = details as List <Detail>; dtList = Util.ToDataTable <Detail>(ListDetail); dtList.Columns.Add(COL_SCANNED); foreach (DataRow row in dtList.Rows) { row[COL_SCANNED] = 0; } dgCuonList.DataSource = dtList; dgCuonList.TableStyles.Clear(); DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = dtList.TableName; foreach (DataColumn item in dtList.Columns) { DataGridTextBoxColumn tbcName = new DataGridTextBoxColumn(); switch (item.ColumnName) { case "vnpt_pn": { tbcName.MappingName = item.ColumnName; tbcName.HeaderText = "VNPT P/N"; tbcName.Width = 100; } break; case "total_export": { tbcName.MappingName = item.ColumnName; tbcName.HeaderText = "Đã xuất"; tbcName.Width = 40; } break; case "total_request": { tbcName.MappingName = item.ColumnName; tbcName.HeaderText = "Tổng"; tbcName.Width = 40; } break; case COL_SCANNED: { tbcName.MappingName = item.ColumnName; tbcName.HeaderText = "Đã quét"; tbcName.Width = 40; } break; case "part_id": { tbcName.Width = -1; } break; default: { tbcName.Width = 40; } break; } if (tbcName.MappingName != "") { tbcName.MappingName = item.ColumnName; tbcName.HeaderText = item.ColumnName; } tableStyle.GridColumnStyles.Add(tbcName); } dgCuonList.TableStyles.Add(tableStyle); dgCuonList.Refresh(); btnReset.Enabled = true; } catch (Exception ex) { MessageBox.Show("Khong lay duoc du lieu"); txtMaXuatKho.Text = DEFAULT_TXT_MAXK; _exp_code = ""; } } else { //if (Util.CleanStr(res.RawText) != "") MessageBox.Show(Util.CleanStr(res.RawText)); MessageBox.Show(res.RawText); txtMaXuatKho.Text = DEFAULT_TXT_MAXK; _exp_code = ""; } }