Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string url   = "update_location_by_code";
                var    paras = new
                {
                    code = temCuon.IdCuon,
                    inventory_location_id = temViTri.ID
                };
                ApiResponse res = HTTP.Post(url, paras);

                if (res.Status)
                {
                    MessageBox.Show("Da cap nhat vitri");
                    ResetForm();
                }
                else
                {
                    MessageBox.Show(res.Message);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        private void UpdateFormInfoExport()
        {
            //Update Package Cancel to ERP
            string      maXuatKho = txtMaXuatKho.Text.TrimStart().TrimEnd();
            ApiResponse res       = new ApiResponse();

            res.Status = false;

            var listPackage = listCodeFromListObject(listExportCancel);

            try
            {
                string url = "removePackageXuatKho";
                if (this._checkOther == 1)
                {
                    url = "removePackageXuatKhoOther";
                }
                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 huy thung/cuon", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }

            //Done
            this.listExportCancel.Clear();

            //refresh data
            LoadData(maXuatKho);
        }
Пример #3
0
        private void btnFinish_Click(object sender, EventArgs e)
        {
            string url = "updateListXuatKhoLK";

            string dsCuon = string.Join("-", listScanned.ToArray());

            var paras = new
            {
                ma_xuat_kho = _exp_code,
                list_cuon   = dsCuon
            };

            try
            {
                ApiResponse res = HTTP.Post(url, paras);

                if (res.Status)
                {
                    //update trang thai cua lenh export kho
                    MessageBox.Show("Da luu thanh cong");
                    ResetForm();
                    dtListCuon.Rows.Clear();
                }
                else
                {
                    MessageBox.Show("Loi mang, hay thu lai lan nua");
                }
            }catch (Exception ex) {
                MessageBox.Show("Khong co ket noi mang", "Loi mang", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }
Пример #4
0
        private void GetListPackageDaXuat()
        {
            if (maXuatKho != "")
            {
                ApiResponse res = new ApiResponse();
                res.Status = false;
                //Load danh sach package
                try
                {
                    string url = "getPackageXuatKho";
                    if (this._checkOther == 1)
                    {
                        url = "getPackageXuatKhoOther";
                    }
                    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
                    {
                        _listExport = JsonConvert.DeserializeObject <List <PackageInfo> >(res.RawText, new JsonSerializerSettings
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        foreach (PackageInfo item in _listExport)
                        {
                            item.status = "DaXuat";
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Khong lay duoc package da xuat");
                    }
                }
                else
                {
                    if (Util.CleanStr(res.RawText) != "")
                    {
                        MessageBox.Show(Util.CleanStr(res.RawText));
                    }
                }
            }
        }
Пример #5
0
        private void ScanCode(string dcdData)
        {
            if (dcdData.StartsWith("["))
            {
                #region Scan Package/Unit ID new
                if (this._LocationInfo == null)
                {
                    MessageBox.Show("Request scan location before scan the package!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                try
                {
                    string       scanValue    = dcdData.Replace(System.Environment.NewLine, "").Trim();
                    LabelPackage labelPackage = new LabelPackage(scanValue);

                    //Util.Logs(labelPackage.PackageId);

                    if (labelPackage.PackageId != null && labelPackage.PackageId != "")
                    {
                        //Check package exists in inventory
                        ApiResponse res = new ApiResponse();
                        res.Status = false;
                        string url = "";
                        int    _id = 0; bool isPackage = true;
                        if (Util.getTypePackage(labelPackage.PackageId, null) % 2 == 0)
                        {
                            isPackage = false;
                            Lots lot     = new Lots();
                            Lots lotInfo = lot.getInfo(labelPackage.PackageId);
                            if (lotInfo == null)
                            {
                                MessageBox.Show("Unit ID is not exists in inventory !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }
                            else
                            {
                                url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";lotId==" + lotInfo.id.ToString();
                                _id = lotInfo.id;
                            }
                        }
                        else if (Util.getTypePackage(labelPackage.PackageId, null) % 2 != 0)
                        {
                            isPackage = true;
                            Packages package     = new Packages();
                            Packages packageInfo = package.getInfo(labelPackage.PackageId);
                            if (packageInfo == null)
                            {
                                MessageBox.Show("Package is not exists in inventory !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }
                            else
                            {
                                url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";packageId==" + packageInfo.id.ToString();
                                _id = packageInfo.id;
                            }
                        }
                        if (url.Length == 0)
                        {
                            MessageBox.Show("Wrong Package/Unit ID QRCode format !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }

                        try
                        {
                            res = HTTP.GetJson(url);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                        List <AdjustmentDetail> ListDetail;
                        if (res.Status && Util.IsJson(res.RawText))
                        {
                            List <AdjustmentDetail> RootObject = JsonConvert.DeserializeObject <List <AdjustmentDetail> >(res.RawText, new JsonSerializerSettings
                            {
                                NullValueHandling = NullValueHandling.Ignore
                            });

                            ListDetail = RootObject as List <AdjustmentDetail>;

                            if (checkExistsInTable(labelPackage.PackageId))
                            {
                                return;
                            }
                            else
                            {
                                if (ListDetail.Count == 0)
                                {
                                    DialogResult mgb = new DialogResult();
                                    mgb = MessageBox.Show("Package/Unit ID is not exists in inventory adjustment! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                    if (mgb != DialogResult.Yes)
                                    {
                                        return;
                                    }

                                    addPackageFromStock(_id, labelPackage.PackageId, isPackage, labelPackage.ProductName, _LocationInfo.barcode, null, 0);
                                    //addPackageToList(labelPackage.PackageId, 0, labelPackage.ProductName, _LocationInfo.barcode);

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                                else
                                {
                                    if (labelPackage.PackageId.StartsWith(PREFIX_LOT) || ListDetail.Count == 1)
                                    {
                                        addPackageToList(ListDetail[0]);
                                    }
                                    else if (labelPackage.PackageId.StartsWith(PREFIX_PACK))
                                    {
                                        foreach (AdjustmentDetail item in ListDetail)
                                        {
                                            addPackageToList(item);
                                        }
                                    }

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong Package/Unit ID QRCode format !");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error scan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                #endregion
            }
            else if (dcdData.Trim().StartsWith("PN:"))
            {
                #region Scan Package/Unit ID old
                if (_LocationInfo == null)
                {
                    MessageBox.Show("Request scan location before scan the package!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                try
                {
                    string  scanValue = dcdData.Replace(System.Environment.NewLine, "").Trim();
                    TemCuon temCuon   = new TemCuon(scanValue);

                    if (temCuon.IdCuon != null && temCuon.IdCuon != "")
                    {
                        //Check package exists in inventory
                        ApiResponse res = new ApiResponse();
                        res.Status = false;
                        string url = "";
                        int    _id = 0; bool isPackage = true;

                        if (Convert.ToInt32(temCuon.Type) == 0)
                        {
                            isPackage = false;
                            Lots lot     = new Lots();
                            Lots lotInfo = lot.getInfo(temCuon.IdCuon);
                            if (lotInfo == null)
                            {
                                DialogResult mgb = new DialogResult();
                                mgb = MessageBox.Show("Uid is not exists in inventory! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                if (mgb != DialogResult.Yes)
                                {
                                    return;
                                }
                                if (checkExistsInTable(temCuon.IdCuon, Convert.ToInt32(temCuon.Type)))
                                {
                                    return;
                                }
                                addPackageToList(null, temCuon.IdCuon, Convert.ToDouble(temCuon.SoLuong), temCuon.VnptPn, _LocationInfo.barcode, temCuon.Type);
                            }
                            url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";lotId==" + lotInfo.id.ToString();
                            _id = lotInfo.id;
                        }
                        else if (Convert.ToInt32(temCuon.Type) == 1)
                        {
                            isPackage = true;
                            Packages package     = new Packages();
                            Packages packageInfo = package.getInfo(temCuon.IdCuon);
                            if (packageInfo == null)
                            {
                                DialogResult mgb = new DialogResult();
                                mgb = MessageBox.Show("Package is not exists in inventory! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                if (mgb != DialogResult.Yes)
                                {
                                    return;
                                }
                                if (checkExistsInTable(temCuon.IdCuon, Convert.ToInt32(temCuon.Type)))
                                {
                                    return;
                                }
                                addPackageToList(temCuon.IdCuon, null, Convert.ToDouble(temCuon.SoLuong), temCuon.VnptPn, _LocationInfo.barcode, temCuon.Type);
                            }
                            url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";packageId==" + packageInfo.id.ToString();
                            _id = packageInfo.id;
                        }
                        if (url.Length == 0)
                        {
                            MessageBox.Show("Wrong Package/Unit ID QRCode format !"); return;
                        }

                        try
                        {
                            res = HTTP.GetJson(url);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                        List <AdjustmentDetail> ListDetail;
                        if (res.Status && Util.IsJson(res.RawText))
                        {
                            List <AdjustmentDetail> RootObject = JsonConvert.DeserializeObject <List <AdjustmentDetail> >(res.RawText, new JsonSerializerSettings
                            {
                                NullValueHandling = NullValueHandling.Ignore
                            });

                            ListDetail = RootObject as List <AdjustmentDetail>;

                            if (checkExistsInTable(temCuon.IdCuon, Convert.ToInt32(temCuon.Type)))
                            {
                                return;
                            }
                            else
                            {
                                if (ListDetail.Count == 0)
                                {
                                    DialogResult mgb = new DialogResult();
                                    mgb = MessageBox.Show("Package/Unit ID is not exists in inventory adjustment! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                    if (mgb != DialogResult.Yes)
                                    {
                                        return;
                                    }

                                    addPackageFromStock(_id, temCuon.IdCuon, isPackage, temCuon.VnptPn, _LocationInfo.barcode, temCuon.Type, Convert.ToDouble(temCuon.SoLuong));
                                    //addPackageToList(temCuon.IdCuon, 0, temCuon.VnptPn, _LocationInfo.barcode, Convert.ToInt32(temCuon.Type));

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                                else
                                {
                                    if (Convert.ToInt32(temCuon.Type) == 0 || ListDetail.Count == 1)
                                    {
                                        addPackageToList(ListDetail[0]);
                                    }
                                    else if (Convert.ToInt32(temCuon.Type) == 1)
                                    {
                                        foreach (AdjustmentDetail item in ListDetail)
                                        {
                                            addPackageToList(item);
                                        }
                                    }

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong Package/Unit ID QRCode format !");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error scan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                #endregion
            }
            else if (Util.OnlyHexInString(dcdData.Trim()))
            {
                #region scan serial number

                string SerialNumber = dcdData.Trim();
                checkScan(null, SerialNumber, null);

                #endregion
            }
            else
            {
                #region Scan location
                locationBarcode = dcdData.Replace(System.Environment.NewLine, "").Trim();
                try
                {
                    ApiResponse res = new ApiResponse();
                    res.Status = false;

                    string url   = "locations/check-child";
                    var    param = new
                    {
                        locationId = this._Adjustment.locationId,
                        barcode    = locationBarcode
                    };
                    res = HTTP.Post(url, param);
                    if (res.Status)
                    {
                        if (Convert.ToBoolean(res.RawText))
                        {
                            if (_LocationInfo != null)
                            {
                                DialogResult mgb = new DialogResult();
                                mgb = MessageBox.Show("Are you sure you want to update new scan location?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                if (mgb != DialogResult.Yes)
                                {
                                    return;
                                }
                            }

                            _LocationInfo = getLocationInfo(locationBarcode);
                            if (_LocationInfo == null)
                            {
                                return;
                            }

                            this.lblLocationBarcode.Text = _LocationInfo.name;

                            //enable button save
                            if (this.dtList.Rows.Count > 0 && !btnSave.Enabled)
                            {
                                btnSave.Enabled = true;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Location is not exists in adjustment name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            //btnSave.Enabled = false;
                            //this.dtList.Rows.Clear();
                            //this.dgCuonList.Refresh();
                            this.locationBarcode = null;
                            //this.lblLocationBarcode.Text = null;
                        }
                    }
                    else
                    {
                        //btnSave.Enabled = false;
                        //this.dtList.Rows.Clear();
                        //this.dgCuonList.Refresh();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error during load location information !");
                }
                #endregion
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        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         = "";
            }
        }
Пример #8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //check vi tri
            if (temViTri == null)
            {
                MessageBox.Show("Hãy quét vào tem vị trí", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            else if (listTemThungThanhPham.Count == 0)
            {
                MessageBox.Show("Hãy quét vào tem thùng thành phẩm", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            else
            {
                try
                {
                    btnSave.Enabled    = false;
                    btnReset.Enabled   = false;
                    dgListCuon.Enabled = false;

                    string url = "update_location_by_code";

                    var temCuons = listCodeFromListObject(listTemThungThanhPham);

                    var paras = new
                    {
                        code = temCuons,
                        inventory_location_id = temViTri.ID
                    };

                    ApiResponse res = HTTP.Post(url, paras);

                    if (res.Status)
                    {
                        ApiModel resApi = JsonConvert.DeserializeObject <ApiModel>(res.RawText, new JsonSerializerSettings
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        });

                        if (resApi.code == 200)
                        {
                            MessageBox.Show("Lưu thành công");
                            ResetForm();
                        }
                        else
                        {
                            //MessageBox.Show(resApi.message, "Co loi xay ra", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            MessageBox.Show(resApi.message);
                            btnSave.Enabled    = true;
                            btnReset.Enabled   = true;
                            dgListCuon.Enabled = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Co loi xay ra, hay thu lai");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Không có kết nối mạng", "Loi mang", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    btnSave.Enabled    = true;
                    btnReset.Enabled   = true;
                    dgListCuon.Enabled = true;
                }
            }
        }
Пример #9
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            string maXuatKho = txtMaXuatKho.Text.TrimStart().TrimEnd();

            _exp_code = txtMaXuatKho.Text;

            btnLoad.Enabled  = false;
            btnReset.Enabled = false;
            listScanned.Clear();
            dtListCuon.Rows.Clear();

            if (maXuatKho != "")
            {
                ApiResponse res = new ApiResponse();
                res.Status = false;
                //Load danh sach linh kien
                try
                {
                    //string url = "getListThungXuatKho";
                    string url   = "getListCuonXuatKho";
                    var    paras = new
                    {
                        ma_xuat_kho = maXuatKho
                    };
                    res = HTTP.Post(url, paras);
                }
                catch (Exception ex) {
                    MessageBox.Show("Loi tai du lieu xuat kho", "Loi mang", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }

                if (res.Status && Util.IsJson(res.RawText))
                {
                    try
                    {
                        List <CuonModel> listCuon = JsonConvert.DeserializeObject <List <CuonModel> >(res.RawText, new JsonSerializerSettings
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        });

                        btnReset.Enabled = true;

                        //lblChuaQuet.Text = chuaQuet.ToString();

                        dtListCuon = Util.ToDataTable <CuonModel>(listCuon);

                        dtListCuon.Columns.Add(COL_STATUS);
                        dtListCuon.Columns.Add(COL_ACTION);

                        foreach (DataRow row in dtListCuon.Rows)
                        {
                            if (row["Scanned"].ToString() == "1")
                            {
                                row[COL_STATUS] = "DX";
                            }
                            else
                            {
                                row[COL_STATUS] = "";
                            }
                            row[COL_ACTION] = "";
                        }

                        dgCuonList.DataSource = dtListCuon;
                        dgCuonList.TableStyles.Clear();
                        DataGridTableStyle tableStyle = new DataGridTableStyle();
                        tableStyle.MappingName = dtListCuon.TableName;
                        foreach (DataColumn item in dtListCuon.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 "Code":
                            {
                                tbcName.MappingName = item.ColumnName;
                                tbcName.HeaderText  = "Id Cuon";
                                tbcName.Width       = 65;
                            } break;

                            case "Quantity":
                            {
                                tbcName.Width = -1;
                            } break;

                            case "Thung":
                            {
                                tbcName.Width = 65;
                            } break;

                            case "Scanned":
                            {
                                tbcName.Width = -1;
                            } break;

                            case "ThungType":
                            {
                                tbcName.Width = -1;
                            } break;

                            case COL_STATUS:
                            {
                                tbcName.MappingName = item.ColumnName;
                                tbcName.HeaderText  = "Trang thai";
                                tbcName.Width       = 30;
                            } break;

                            case COL_ACTION:
                            {
                                tbcName.MappingName = item.ColumnName;
                                tbcName.HeaderText  = "Huy";
                                tbcName.Width       = 25;
                            } break;

                            default:
                            {
                                tbcName.Width = 65;
                            } break;
                            }

                            if (tbcName.MappingName != "")
                            {
                                tbcName.MappingName = item.ColumnName;
                                tbcName.HeaderText  = item.ColumnName;
                            }

                            tableStyle.GridColumnStyles.Add(tbcName);

                            dangQuet = true;
                        }

                        dgCuonList.TableStyles.Add(tableStyle);

                        dgCuonList.Refresh();

                        ScanInfo();
                    }
                    catch (Exception ex)
                    {
                        //btnLoad.Enabled = true;
                        MessageBox.Show("Khong lay duoc du lieu");
                        txtMaXuatKho.Text = DEFAULT_TXT_MAXK;
                        _exp_code         = "";
                    }
                }
                else
                {
                    //btnLoad.Enabled = true;
                    if (Util.CleanStr(res.RawText) != "")
                    {
                        MessageBox.Show(Util.CleanStr(res.RawText));
                    }
                    txtMaXuatKho.Text = DEFAULT_TXT_MAXK;
                    _exp_code         = "";
                }
            }
            else
            {
                txtMaXuatKho.Focus();
            }
        }