Example #1
0
        /// <summary>
        /// Insert Log
        /// </summary>
        /// <param name="boxId"></param>
        private void InsertLog(string boxId)
        {
            if (!string.IsNullOrEmpty(txtProductionID.Text.Trim()) ||
                !string.IsNullOrEmpty(txtMacAddress.Text.Trim()) ||
                !string.IsNullOrEmpty(txtJudge.Text.Trim()))
            {
                int    lineId      = Program.CurrentUser.LineID;
                int    operationId = Program.CurrentUser.OperationID;
                string operatorId  = Program.CurrentUser.OperatorCode;
                bool   judge       = txtJudge.Text.Trim() == "1";

                if (operationId == 1)
                {
                    var logs = _oqcService.GetLogsByBoxId(boxId).ToList();
                    // Nếu Box có dữ liệu của PCB
                    if (logs.Any())
                    {
                        var log = logs.FirstOrDefault(l => l.ProductionID == txtProductionID.Text);
                        // Nếu PCB mới bắn vào chưa có trong Box
                        if (log == null)
                        {
                            if (!CheckProductionId(txtProductionID.Text, lblCurentModel.Text, lblSerialNo.Text))
                            {
                                SetErrorStatus(true, "NG", $"Error {lblCurentModel.Text} !\nPCB [{txtProductionID.Text}]\nnày khác với các PCB trong Box [{boxId}].\nVui lòng kiểm tra lại!");
                                txtProductionID.SelectAll();
                                Ultils.EditTextErrorNoMessage(txtProductionID);
                                txtJudge.ResetText();
                                txtMacAddress.ResetText();
                                txtBoxID.ResetText();
                            }
                            else
                            {
                                string tmp           = lblQuantityModel.Text.Replace("/", "");
                                int    countPcbInBox = int.Parse(lblCountPCB.Text);
                                int    quantity      = int.Parse(tmp);

                                if (countPcbInBox == quantity)
                                {
                                    SetErrorStatus(true, "OK", "Thùng đã đủ số lượng, vui lòng kiểm tra lại!");
                                    ResetControls();
                                }
                                else
                                {
                                    try
                                    {
                                        _iqcService.InsertLogs(txtProductionID.Text, lineId, txtMacAddress.Text, boxId, null, null, 1, operatorId);

                                        if (!_iqcService.CheckResultExits(txtProductionID.Text, operationId))
                                        {
                                            _iqcService.InsertResult(txtProductionID.Text, operationId, judge, operatorId);
                                        }
                                        else
                                        {
                                            _iqcService.UpdateResult(txtProductionID.Text, operationId, judge, operatorId);
                                        }
                                        var refeshData = _iqcService.GetLogs(boxId).ToList();
                                        gridControlData.Refresh();
                                        gridControlData.DataSource = refeshData;
                                        lblCountPCB.Text           = refeshData.Count.ToString(CultureInfo.InvariantCulture);

                                        SetSuccessStatus(true, "PASS", string.Format("Thêm thành công!\nPCB [{0}]", txtProductionID.Text));
                                        ResetControls();
                                    }
                                    catch (Exception ex)
                                    {
                                        SetErrorStatus(true, "NG", "Error Insert! \n" + ex.Message);
                                        ResetControls();
                                    }
                                }
                            }
                        }
                        // Nếu có rồi thì thống báo lỗi
                        else
                        {
                            SetErrorStatus(true, "NG", $"PCB [{txtProductionID.Text}] này đã có trong Box rồi.\nVui lòng kiểm tra lại");
                            ResetControls();
                            var refeshData = _oqcService.GetLogsByBoxId(boxId);
                            gridControlData.Refresh();
                            gridControlData.DataSource = refeshData;
                        }
                    }
                    // Nếu Box chưa có dữ liệu gì, thực hiện insert
                    else
                    {
                        try
                        {
                            _iqcService.InsertLogs(txtProductionID.Text, lineId, txtMacAddress.Text, boxId, null, null, 1, operatorId);

                            if (!_iqcService.CheckResultExits(txtProductionID.Text, operationId))
                            {
                                _iqcService.InsertResult(txtProductionID.Text, operationId, judge, operatorId);
                            }
                            else
                            {
                                _iqcService.UpdateResult(txtProductionID.Text, operationId, judge, operatorId);
                            }
                            var refeshData = _iqcService.GetLogs(boxId).ToList();
                            gridControlData.Refresh();
                            gridControlData.DataSource = refeshData;
                            lblCountPCB.Text           = refeshData.Count.ToString(CultureInfo.InvariantCulture);

                            SetSuccessStatus(true, "PASS", string.Format("Thêm thành công!\nPCB [{0}]", txtProductionID.Text));
                            ResetControls();
                        }
                        catch (Exception ex)
                        {
                            SetErrorStatus(true, "NG", "Error Insert! \n" + ex.Message);
                            ResetControls();
                        }
                    }
                }
                else if (operationId >= 2)
                {
                    _iqcService.UpdateLogs(txtProductionID.Text, lineId, txtMacAddress.Text, boxId, null, null, 1, operatorId);
                    _iqcService.InsertResult(txtProductionID.Text, operationId, judge, operatorId);

                    var refeshData = _iqcService.GetLogs(boxId).ToList();
                    gridControlData.Refresh();
                    gridControlData.DataSource = refeshData;
                    lblCountPCB.Text           = refeshData.Count.ToString(CultureInfo.InvariantCulture);

                    SetSuccessStatus(true, "PASS", string.Format("Thành công!\nPCB [{0}] vừa được bắn lại lần {1}", txtProductionID.Text, operationId));
                    ResetControls();
                }
            }
            else
            {
                SetErrorStatus(true, "NG", "Vui lòng nhập đủ thông tin!");
                txtProductionID.Focus();
            }
        }