コード例 #1
0
ファイル: FormMain.cs プロジェクト: imatary/work
        /// <summary>
        /// Insert Log
        /// </summary>
        /// <param name="boxId"></param>
        private void InsertLog(string boxId)
        {
            if (!string.IsNullOrEmpty(txtProductID.Text.Trim()) ||
                !string.IsNullOrEmpty(txtBoxID.Text.Trim()) ||
                !string.IsNullOrEmpty(txtModelUMC.Text.Trim()))
            {
                int    lineId       = Program.CurrentUser.LineID;
                string operatorId   = Program.CurrentUser.OperatorCode;
                string productionId = txtProductID.Text.Trim();

                string status = null;
                bool   judge  = false;
                if (checkPASS.Checked == true)
                {
                    status = "P";
                    judge  = true;
                }
                if (checkNG.Checked == true)
                {
                    status = "F";
                    judge  = false;
                }
                var logs = _context.Set <Nichicon>().Where(n => n.BoxID == boxId).ToList();
                // Nếu Box có dữ liệu của PCB
                if (logs.Any())
                {
                    var log = logs.SingleOrDefault(l => l.ProductionID == productionId);
                    // Nếu PCB mới bắn vào chưa có trong Box
                    if (log == null)
                    {
                        var checkModelInBox = logs.FirstOrDefault();
                        // Nếu Production ID, có Model giống với Model hiện tại
                        if (productionId.Contains(checkModelInBox.ModelName))
                        {
                            string tmp           = lblQuantityModel.Text.Replace("/", "");
                            int    countPcbInBox = int.Parse(lblCountPCB.Text);
                            int    quantity      = int.Parse(tmp);

                            if (logs.Count == quantity)
                            {
                                SetErrorStatus("NG", $"Box [{txtBoxID.Text}] đã đủ số lượng. Vui lòng kiểm tra lại!");
                                Ultils.EditTextErrorNoMessage(txtBoxID);
                                EnableBoxIDWidthModel(true);
                                txtProductID.ResetText();
                            }
                            else
                            {
                                try
                                {
                                    // Insert
                                    Add(productionId, lineId, boxId, modelID, txtModelUMC.Text, operatorId, judge);

                                    Ultils.CreateFileLog(lblCurentModel.Text, productionId, status, Program.CurrentUser.ProcessID, _dateTimeCheck);
                                    Ultils.CreateFileLogDirModelName(lblCurentModel.Text, productionId, status, Program.CurrentUser.ProcessID, _dateTimeCheck);
                                    logs = _context.Set <Nichicon>().Where(n => n.BoxID == boxId).ToList();
                                    gridControlData.Refresh();
                                    gridControlData.DataSource = logs;
                                    lblCountPCB.Text           = logs.Count.ToString(CultureInfo.InvariantCulture);

                                    SetSuccessStatus("OK", $"Thành công!\nPCB [{txtProductID.Text}]");
                                    ResetControls();
                                    if (logs.Count() == quantity)
                                    {
                                        SetErrorStatus("NG", $"Box [{txtBoxID.Text}] đã đủ số lượng. Vui lòng lấy box mới!");
                                        Ultils.EditTextErrorNoMessage(txtBoxID);
                                        EnableBoxIDWidthModel(true);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SetErrorStatus("NG", "Model chưa có trong hệ thống!\nVui lòng nhập model này vào, và thử lại. \n" + ex.Message);
                                    ResetControls();
                                }
                            }
                        }
                        else
                        {
                            SetErrorStatus("NG", "Sai Model! Vui lòng kiểm tra và thử lại!");
                            Ultils.EditTextErrorNoMessage(txtProductID);
                            ResetControls();
                            logs = _context.Set <Nichicon>().Where(n => n.BoxID == boxId).ToList();
                            gridControlData.Refresh();
                            gridControlData.DataSource = logs;
                            lblCountPCB.Text           = logs.Count.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                    // Nếu có rồi thì thống báo lỗi
                    else
                    {
                        SetErrorStatus("NG", $"PCB [{txtProductID.Text}] này đã có trong Box rồi.\nVui lòng kiểm tra lại");
                        ResetControls();
                        gridControlData.Refresh();
                        gridControlData.DataSource = logs;
                        lblCountPCB.Text           = logs.Count.ToString(CultureInfo.InvariantCulture);
                    }
                }
                // Nếu Box chưa có dữ liệu gì, thực hiện insert
                else
                {
                    try
                    {
                        // Insert
                        Add(productionId, lineId, boxId, modelID, txtModelUMC.Text, operatorId, judge);

                        Ultils.CreateFileLog(lblCurentModel.Text, productionId, status, Program.CurrentUser.ProcessID, _dateTimeCheck);
                        Ultils.CreateFileLogDirModelName(lblCurentModel.Text, productionId, status, Program.CurrentUser.ProcessID, _dateTimeCheck);
                        logs = _context.Set <Nichicon>().Where(n => n.BoxID == boxId).ToList();
                        gridControlData.Refresh();
                        gridControlData.DataSource = logs;
                        lblCountPCB.Text           = logs.Count.ToString(CultureInfo.InvariantCulture);

                        SetSuccessStatus("OK", string.Format("Thêm thành công!\nPCB [{0}]", productionId));
                        ResetControls();
                    }
                    catch (Exception ex)
                    {
                        SetErrorStatus("NG", "Error Insert! \n" + ex.Message);
                        ResetControls();
                    }
                }
            }
            else
            {
                SetErrorStatus("NG", "Vui lòng nhập đủ thông tin!");
                EnableBoxIDWidthModel(true);
                txtBoxID.Focus();
            }
        }
コード例 #2
0
ファイル: FormLogin.cs プロジェクト: imatary/work
 private void txtPassword_TextChanged(object sender, EventArgs e)
 {
     Ultils.IsNullOrEmpty(txtPassword, errorProvider1);
 }
コード例 #3
0
        private void txtBarcode_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!Ultils.IsNullOrEmpty(txtBarcode))
                {
                    DisplayMessage("NG", "Vui lòng bắn vào Barcode");
                    return;
                }
                else
                {
                    DateTime dateServer = NICHICON_BUS.GetDateTimeFormSqlServer();
                    string   boardNo    = txtBarcode.Text.Trim();
                    string   boxId      = txtBoxID.Text.Trim();

                    if (boardNo.Length == rule_items.LENGTH)
                    {
                        string key = boardNo.Substring(0, rule_items.CONTENT_LENGTH);
                        if (key == rule_items.CONTENT)
                        {
                            string checkExists = NICHICON_BUS.CheckBoardNOExists(boardNo);
                            if (checkExists == null)
                            {
                                var barcode = new NICHICON()
                                {
                                    ProductionID = boardNo,
                                    LineID       = 0,
                                    BoxID        = boxId,
                                    ModelID      = model.ModelID,
                                    ModelName    = model.ModelName,
                                    DateCheck    = dateServer.Date,
                                    TimeCheck    = dateServer.ToShortTimeString(),
                                    OperatorCode = Program.CurrentUser.ID,
                                    OperatorName = Program.CurrentUser.NAME,
                                    JudgeResult  = chkOK.Checked == true ? "OK" : "NG"
                                };
                                List <NICHICON> data = new List <NICHICON>();
                                data = NICHICON_BUS.GetAll(boxId);
                                if (data.Count > 0)
                                {
                                    if (data.Count >= model.Quantity)
                                    {
                                        txtBoxID.Enabled = true;
                                        txtBoxID.ResetText();
                                        txtBoxID.Focus();
                                        DisplayMessage("WARNING", $"Thùng [{boxId}] đã đầy. Vui lòng lấy thùng khác!");
                                        return;
                                    }

                                    string old_key = data[0].ProductionID.Substring(0, rule_items.CONTENT_LENGTH);
                                    if (old_key == key)
                                    {
                                        try
                                        {
                                            int result = NICHICON_BUS.Add(barcode);
                                            if (result > 0)
                                            {
                                                data = NICHICON_BUS.GetAll(boxId);
                                                txtBarcode.ResetText();
                                                txtBarcode.Focus();

                                                var app = Process.GetProcesses().Where(p => p.MainWindowTitle == process).FirstOrDefault();
                                                // Gửi dữ liệu sang phần mềm khác
                                                if (app != null)
                                                {
                                                    ActiveWindows(process);
                                                    SendKeys.Send(boardNo);
                                                    Thread.Sleep(150);
                                                    SendKeys.Send("{ENTER}");
                                                }

                                                DisplayMessage("OK", $"Lưu thành công [{boardNo}]!");
                                                if (writeLog == true)
                                                {
                                                    string status = chkOK.Checked == true ? "P" : "F";
                                                    Ultils.CreateFileLog(model.ModelName, boardNo, status, "VI_NIC", dateServer);
                                                }

                                                Thread.Sleep(250);
                                                ActiveWindows(this.Text);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            txtBarcode.ResetText();
                                            txtBarcode.Focus();

                                            DisplayMessage("NG", "Lỗi!" + ex.Message + "\nVui lòng kiểm tra và bắn lại!");
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        txtBarcode.ResetText();
                                        txtBarcode.Focus();
                                        DisplayMessage("NG", "Model khác với model trong thùng. Vui lòng kiểm tra và bắn lại!");
                                        return;
                                    }
                                }
                                // Nếu chưa có thì thêm vào CSDL
                                else
                                {
                                    try
                                    {
                                        int result = NICHICON_BUS.Add(barcode);
                                        if (result > 0)
                                        {
                                            data = NICHICON_BUS.GetAll(boxId);
                                            txtBarcode.ResetText();
                                            txtBarcode.Focus();


                                            var app = Process.GetProcesses().Where(p => p.MainWindowTitle == process).FirstOrDefault();
                                            // Gửi dữ liệu sang phần mềm khác
                                            if (app != null)
                                            {
                                                ActiveWindows(process);
                                                SendKeys.Send(boardNo);
                                                Thread.Sleep(150);
                                                SendKeys.Send("{ENTER}");
                                            }

                                            DisplayMessage("OK", $"Lưu thành công [{boardNo}]!");

                                            if (writeLog == true)
                                            {
                                                string status = chkOK.Checked == true ? "P" : "F";
                                                Ultils.CreateFileLog(model.ModelName, boardNo, status, "VI_NIC", dateServer);
                                            }

                                            Thread.Sleep(250);
                                            ActiveWindows(this.Text);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        txtBarcode.ResetText();
                                        txtBarcode.Focus();

                                        DisplayMessage("NG", "Lỗi!" + ex.Message + "\nVui lòng kiểm tra và bắn lại!");
                                        return;
                                    }
                                }

                                int count = data.Count;
                                if (data.Count == model.Quantity)
                                {
                                    txtBoxID.Enabled = true;
                                    txtBoxID.ResetText();
                                    txtBoxID.Focus();
                                    DisplayMessage("WARNING", $"Thùng [{boxId}] đã đầy. Vui lòng lấy thùng khác!");
                                    return;
                                }

                                lblQuantity.Text = $"{count}/{model.Quantity}";

                                // Tải dữ liệu lên Gridview
                                dataGridView1.DataSource = data;
                            }
                            else
                            {
                                txtBarcode.ResetText();
                                txtBarcode.Focus();
                                DisplayMessage("NG", $"Board [{boardNo}] đã được bắn trước đó. Vui lòng kiểm tra và bắn lại!");
                                return;
                            }
                        }
                        else
                        {
                            txtBarcode.ResetText();
                            txtBarcode.Focus();
                            DisplayMessage("NG", "Sai Model. Vui lòng kiểm tra và bắn lại!");
                            return;
                        }
                    }
                    else
                    {
                        txtBarcode.ResetText();
                        txtBarcode.Focus();
                        DisplayMessage("NG", "Barcode không đúng định dạng. Vui lòng kiểm tra và bắn lại!");
                        return;
                    }
                }
            }
        }