示例#1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (errorId != 0)
         {
             if (MessageBox.Show("Bạn có muốn xoá không?", "Xoá đối tượng", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 var result = BLLError.Delete(errorId);
                 if (result.IsSuccess)
                 {
                     LoadDataForGridError();
                     ResetErrorForm();
                 }
                 MessageBox.Show(result.Messages[0].msg, result.Messages[0].Title);
             }
         }
         else
         {
             MessageBox.Show("Bạn chưa chọn đối tượng để xoá");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
 private void FrmReportErrorOfLineByHours_Load(object sender, EventArgs e)
 {
     try
     {
         errors.AddRange(BLLError.GetAll());
         lines.AddRange(BLLLine.GetLines(AccountSuccess.strListChuyenId.Split(',').Select(x => Convert.ToInt32(x)).ToList()));
         if (lines != null && lines.Count > 0)
         {
             GetDataForCbbHours();
             if (times != null && times.Count > 0)
             {
                 cbbHours.DataSource    = times;
                 cbbHours.DisplayMember = "Name";
                 GetDataChart();
             }
         }
         else
         {
             MessageBox.Show("Lỗi: Không có thông tin Chuyền", "Thông Báo Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message, "Thông Báo Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#3
0
        private void LoadError()
        {
            cbError.DataSource = null;
            var err = BLLError.GetAll();

            cbError.DataSource    = err;
            cbError.DisplayMember = "Name";
            cbError.ValueMember   = "Id";
        }
示例#4
0
 private void LoadDataForGridError()
 {
     try
     {
         gridError.DataSource = BLLError.GetAll();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#5
0
 private void FormSanLuongLoiChuyen_Load(object sender, EventArgs e)
 {
     try
     {
         listError = BLLError.GetAll();//errorDAO.GetListError();
         BuildGridView();
         LoadData();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
 private void FrmReportCountErrorHours_Load(object sender, EventArgs e)
 {
     try
     {
         listError = BLLError.GetAll(); // errorDAO.GetListError();
         GetDataForCbbLine();
         GetDataChart();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
示例#7
0
 public bool AddNangSuatCumLoiOfChuyen(int sttChuyenSanPham, int maChuyen)
 {
     try
     {
         bool   result      = false;
         string dateNow     = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
         var    listCluster = clusterDAO.GetCumOfChuyen(maChuyen);
         if (listCluster != null && listCluster.Count > 0)
         {
             List <string> listQuery = new List <string>();
             foreach (var cluster in listCluster)
             {
                 var listError = BLLError.GetAll(); // errorDAO.GetListError();
                 if (listError != null && listError.Count > 0)
                 {
                     foreach (var error in listError)
                     {
                         string    strSQLCheckExist = "Select Id From NangSuat_CumLoi Where STTChuyenSanPham=" + sttChuyenSanPham + " and IsDeleted=0 and CumId=" + cluster.Id + " and Ngay ='" + dateNow + "' and ErrorId=" + error.Id;
                         DataTable dtCheckExist     = dbclass.TruyVan_TraVe_DataTable(strSQLCheckExist);
                         if (dtCheckExist == null || (dtCheckExist != null && dtCheckExist.Rows.Count == 0))
                         {
                             listQuery.Add("Insert Into NangSuat_CumLoi(Ngay, STTChuyenSanPham, CumId, ErrorId) Values('" + dateNow + "'," + sttChuyenSanPham + ", " + cluster.Id + ", " + error.Id + ")");
                         }
                     }
                 }
             }
             if (listQuery.Count > 0)
             {
                 int rs = dbclass.ExecuteSqlTransaction(listQuery);
                 if (rs > 0)
                 {
                     result = true;
                 }
             }
             else
             {
                 result = true;
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private void FrmCauHinhDocSo_Load(object sender, EventArgs e)
 {
     try
     {
         LoadDataToGridView();
         //LoadCbbSoundInt();
         EnableControlSend(true, false, false, false, false);
         ClearInput();
         EnableInputMSend(false);
         var listError = BLLError.GetAll(); // errorDAO.GetListError();
         cbbError1.DataSource    = listError;
         cbbError1.DisplayMember = "Name";
         cbbError2.DataSource    = listError;
         cbbError2.DisplayMember = "Name";
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
示例#9
0
 private void Save()
 {
     try
     {
         Error error = BuildModel();
         if (error != null)
         {
             var result = BLLError.InsertOrUpdate(error);
             if (result.IsSuccess)
             {
                 ResetErrorForm();
                 LoadDataForGridError();
             }
             MessageBox.Show(result.Messages[0].msg, result.Messages[0].Title);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
示例#10
0
        private void FrmLCDError_Load(object sender, EventArgs e)
        {
            try
            {
                LoadLCDConfig();
                //Get list Chuyen
                listChuyen = chuyenDAO.GetListChuyenInfByListId(AccountSuccess.strListChuyenId);
                if (listChuyen != null && listChuyen.Count > 0)
                {
                    line      = listChuyen.First();
                    titleLCD += " " + line.TenChuyen;
                }


                //Get config information
                listTableLayoutPanelConfig = tableLayoutPanelConfigDAO.GetTableLayoutPanelConfig(tableType);
                //Get config panel
                listPanelConfig = panelConfigDAO.GetPanelConfig(tableType);
                //Get label config
                listLabelConfig = labelConfigDAO.GetLabelConfig(tableType);
                //Get label for tablepanel
                listLabelForTablePanel = labelConfigDAO.GetLabelForTablePanel(tableType);

                modelLCDError = BLLError.GetListGroupErrors();// groupErrorDAO.GetListGroupErrorDetail();

                BuildPanelHeader();
                BuildPanelTitle1();
                BuildPanelContent();
                BuildPanelBody();
                initTimerDateTime();
                LoadDataErorForChuyen();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }
示例#11
0
        /// <summary>
        /// reset keypad tinh san luong rieng theo tung keypad ko cong chung tat ca lai
        /// </summary>
        /// <param name="lineId"></param>
        /// <param name="sttChuyenSanPham"></param>
        /// <param name="errorId"></param>
        /// <param name="typeOfProduction"></param>
        /// <param name="todayStr"></param>
        /// <param name="frmMainNew"></param>
        public static void ResetKeypad_moi(int lineId, int sttChuyenSanPham, int errorId, int typeOfProduction, string todayStr, FrmMainNew frmMainNew)
        {
            try
            {
                var assigns = BLLProductivity.GetProductivitiesInDay(todayStr, lineId);
                if (assigns != null && assigns.Count > 0)
                {
                    for (int i = 0; i < assigns.Count; i++)
                    {
                        if (assigns[i].STTCHuyen_SanPham == sttChuyenSanPham)
                        {
                            var keypads = BLLKeyPad.GetKeyPadInfoByLineId(lineId);
                            if (keypads != null && keypads.Count > 0)
                            {
                                var tdns       = BLLDayInfo.GetByCommoId(sttChuyenSanPham, assigns[i].productId, frmMainNew.todayStr);
                                var btps       = BLLDayInfo.GetBTPNgay(sttChuyenSanPham, frmMainNew.todayStr);
                                int quantities = 0;
                                foreach (var keyPadInfo in keypads)
                                {
                                    if (keyPadInfo.UseTypeId == (int)eUseKeyPadType.OneKeyPadOneObject)
                                    {
                                        var slCuaKeypad = tdns.Where(x => x.EquipmentId == keyPadInfo.EquipmentId).ToList();
                                        var slBTPKeypad = btps.Where(x => x.EquipmentId == keyPadInfo.EquipmentId).ToList();

                                        // frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ClearData + ",,");
                                        switch (typeOfProduction)
                                        {
                                        case (int)eProductOutputType.KCS:
                                            if (keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.All || keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.KCS)
                                            {
                                                quantities  = slCuaKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductIncrease && c.ProductOutputTypeId == (int)eProductOutputType.KCS).Sum(c => c.ThanhPham);
                                                quantities -= slCuaKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductReduce && c.ProductOutputTypeId == (int)eProductOutputType.KCS).Sum(c => c.ThanhPham);
                                                frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + (i + 1) + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.KCS);
                                            }
                                            break;

                                        case (int)eProductOutputType.TC:
                                            if (keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.All || keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.TC)
                                            {
                                                quantities  = slCuaKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductIncrease && c.ProductOutputTypeId == (int)eProductOutputType.TC).Sum(c => c.ThanhPham);
                                                quantities -= slCuaKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductReduce && c.ProductOutputTypeId == (int)eProductOutputType.TC).Sum(c => c.ThanhPham);
                                                frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + (i + 1) + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.TC);
                                            }
                                            break;

                                        case (int)eProductOutputType.BTP:
                                            if (keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.All || keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.BTP)
                                            {
                                                quantities  = slBTPKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.BTPIncrease).Sum(c => c.BTPNgay);
                                                quantities -= slBTPKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.BTPReduce).Sum(c => c.BTPNgay);
                                                frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + (i + 1) + "," + (quantities < 0 ? 0 : quantities) + ",1");
                                            }
                                            break;

                                        case (int)eProductOutputType.Error:
                                            var errorObj = BLLError.GetById(errorId);
                                            quantities  = slCuaKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.ErrorIncrease && c.ErrorId.HasValue && c.ErrorId.Value == errorId).Sum(c => c.ThanhPham);
                                            quantities -= slCuaKeypad.Where(c => c.CommandTypeId == (int)eCommandRecive.ErrorReduce && c.ErrorId.HasValue && c.ErrorId.Value == errorId).Sum(c => c.ThanhPham);
                                            frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductError + "," + (i + 1) + "," + (quantities < 0 ? 0 : quantities) + "," + errorObj.Code);
                                            break;
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
示例#12
0
        /// <summary>
        /// Dong bo lai thong tin keypad cua tat cac cac cum sau khi su ly xong
        /// </summary>
        /// <param name="lineId"></param>
        /// <param name="sttChuyenSanPham"></param>
        /// <param name="errorId"></param>
        /// <param name="typeOfProduction">loai hinh nang suat KCS - TC - BTP -ERROR </param>
        /// <param name="todayStr"></param>
        /// <param name="frmMainNew"></param>
        public static void ResetKeypad(int lineId, int sttChuyenSanPham, int errorId, int typeOfProduction, string todayStr, FrmMainNew frmMainNew)
        {
            try
            {
                // frmMainNew.aaaaa = "";
                var assigns = BLLProductivity.GetProductivitiesInDay(todayStr, lineId);
                if (assigns != null && assigns.Count > 0)
                {
                    for (int i = 0; i < assigns.Count; i++)
                    {
                        if (assigns[i].STTCHuyen_SanPham == sttChuyenSanPham)
                        {
                            var keypads = BLLKeyPad.GetKeyPadInfoByLineId(lineId);
                            if (keypads != null && keypads.Count > 0)
                            {
                                var nxInDay    = BLLProductivity.GetProductivitiesInDay(DateTime.Now, sttChuyenSanPham);
                                int quantities = 0;
                                if (nxInDay != null)
                                {
                                    foreach (var keyPadInfo in keypads)
                                    {
                                        if (keyPadInfo.UseTypeId == (int)eUseKeyPadType.OneKeyPadOneObject)
                                        {
                                            // frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ClearData + ",,");
                                            switch (typeOfProduction)
                                            {
                                            case (int)eProductOutputType.KCS:
                                                if (keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.All || keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.KCS)
                                                {
                                                    //  frmMainNew.aaaaa += " - " + keyPadInfo.EquipmentId.ToString() + "(type:" + keyPadInfo.TypeOfKeypad + ")" + "(typeOfProduction:" + typeOfProduction + ")";
                                                    quantities = (nxInDay.ThucHienNgay - nxInDay.ThucHienNgayGiam);
                                                    frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + (i + 1) + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.KCS);
                                                }
                                                break;

                                            case (int)eProductOutputType.TC:
                                                if (keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.All || keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.TC)
                                                {
                                                    // frmMainNew.aaaaa += " - " + keyPadInfo.EquipmentId.ToString() + "(type:" + keyPadInfo.TypeOfKeypad + ")" + "(typeOfProduction:" + typeOfProduction + ")";
                                                    quantities = (nxInDay.BTPThoatChuyenNgay - nxInDay.BTPThoatChuyenNgayGiam);
                                                    frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + (i + 1) + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.TC);
                                                }
                                                break;

                                            case (int)eProductOutputType.BTP:
                                                if (keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.All || keyPadInfo.TypeOfKeypad == (int)eTypeOfKeypad.BTP)
                                                {
                                                    //  frmMainNew.aaaaa += " - " + keyPadInfo.EquipmentId.ToString() + "(type:" + keyPadInfo.TypeOfKeypad + ")" + "(typeOfProduction:" + typeOfProduction + ")";
                                                    quantities = nxInDay.BTPTang - nxInDay.BTPGiam;
                                                    frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + (i + 1) + "," + (quantities < 0 ? 0 : quantities) + ",1");
                                                }
                                                break;

                                            case (int)eProductOutputType.Error:
                                                var errorObj = BLLError.GetById(errorId);
                                                var err      = nxInDay.Errors.FirstOrDefault(x => x.ErrorId == errorId);
                                                frmMainNew.listDataSendKeyPad.Add(keyPadInfo.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductError + "," + (i + 1) + "," + (err != null ? err.SoLuongTang - err.SoLuongGiam : 0) + "," + errorObj.Code);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
示例#13
0
        /// <summary>
        /// khoi tao lai thong tin keypad cho chuyen
        /// </summary>
        /// <param name="lineId"></param>
        /// <param name="IsResetAllToZero">= true neu reset tat ca ve 0 else neu lay thong tin nang suat hien tai</param>
        /// <param name="frmMainNew"></param>
        /// <returns></returns>
        public static bool ResetKeypad_Moi(int lineId, bool IsResetAllToZero, FrmMainNew frmMainNew)
        {
            try
            {
                var    listMapIdSanPhamNgay = new List <PMS.Data.MapIdSanPhamNgay>();
                string ngay = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;

                var    listStrProductConfig = new List <string>();
                var    errors        = BLLError.GetAll();
                string strListChuyen = lineId + ",";
                var    assigns       = BLLProductivity.GetProductivitiesInDay(ngay, lineId);
                if (assigns != null && assigns.Count > 0)
                {
                    var listStrSend        = new List <string>();
                    var listStrSetSanLuong = new List <string>();
                    var sanluongs          = new List <string>();
                    var sttCSP             = new List <int>();
                    int stt = 0;
                    foreach (var item in assigns)
                    {
                        var mapIdSanPhamNgay = new PMS.Data.MapIdSanPhamNgay();
                        mapIdSanPhamNgay.MaChuyen         = item.LineId;
                        mapIdSanPhamNgay.STTChuyenSanPham = item.STTCHuyen_SanPham;
                        mapIdSanPhamNgay.MaSanPham        = item.productId;
                        stt += 1;
                        mapIdSanPhamNgay.STT  = stt;
                        mapIdSanPhamNgay.Ngay = ngay;
                        listMapIdSanPhamNgay.Add(mapIdSanPhamNgay);
                        string strSend    = mapIdSanPhamNgay.STT.ToString() + ",";
                        string tenSanPham = item.ProductName;
                        if (!string.IsNullOrEmpty(tenSanPham))
                        {
                            if (tenSanPham.Length > 10)
                            {
                                strSend += tenSanPham.Substring(0, 10);
                            }
                            else
                            {
                                strSend += tenSanPham;
                            }
                        }
                        listStrSend.Add(strSend);
                        listStrSetSanLuong.Add(mapIdSanPhamNgay.STT.ToString());
                        sttCSP.Add(item.STTCHuyen_SanPham);
                    }

                    //
                    var keypads = BLLKeyPad.GetKeyPadInfoByLineId(lineId);
                    if (keypads != null && keypads.Count > 0)
                    {
                        if (listStrSend.Count > 0 || listStrSetSanLuong.Count > 0)
                        {
                            foreach (var kp_Obj in keypads)
                            {
                                if (kp_Obj.UseTypeId == (int)eUseKeyPadType.OneKeyPadOneObject)
                                {
                                    frmMainNew.listDataSendKeyPad.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ClearData + ",,");
                                    Thread.Sleep(500);
                                    foreach (var strSend in listStrSend)
                                    {
                                        listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ProductConfig + "," + strSend);
                                    }
                                    if (IsResetAllToZero) // reset keypad + reset so lieu ve 0
                                    {
                                        #region
                                        foreach (var strSend in listStrSetSanLuong)
                                        {
                                            // listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + strSend + ",0,1,");
                                            if (errors != null && errors.Count > 0)
                                            {
                                                foreach (var error in errors)
                                                {
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductError + "," + strSend + ",0," + error.Code);
                                                }
                                            }

                                            switch (kp_Obj.TypeOfKeypad)
                                            {
                                            case (int)eTypeOfKeypad.All:
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + strSend + ",0," + (int)eProductOutputType.KCS);
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + strSend + ",0," + (int)eProductOutputType.TC);
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + strSend + ",0,,");
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + strSend + ",0,1,");
                                                break;

                                            case (int)eTypeOfKeypad.KCS:
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + strSend + ",0," + (int)eProductOutputType.KCS);
                                                break;

                                            case (int)eTypeOfKeypad.TC:
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + strSend + ",0," + (int)eProductOutputType.TC);
                                                break;

                                            case (int)eTypeOfKeypad.BTP:
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + strSend + ",0,,");
                                                listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + strSend + ",0,1,");
                                                break;
                                            }
                                        }
                                        #endregion
                                    }
                                    else   // chi reset keypad van giu so lieu cũ
                                    {
                                        for (int i = 0; i < listStrSetSanLuong.Count; i++)
                                        {
                                            var nxInDay = BLLProductivity.GetProductivitiesInDay(DateTime.Now, sttCSP[i]);
                                            if (nxInDay != null)
                                            {
                                                var tdns = BLLDayInfo.GetByCommoId(sttCSP[i], nxInDay.productId, frmMainNew.todayStr).Where(x => x.EquipmentId == kp_Obj.EquipmentId).ToList();
                                                var btps = BLLDayInfo.GetBTPNgay(sttCSP[i], frmMainNew.todayStr).Where(x => x.EquipmentId == kp_Obj.EquipmentId).ToList();

                                                var quantities = 0;

                                                if (errors != null && errors.Count > 0)
                                                {
                                                    foreach (var error in errors)
                                                    {
                                                        quantities  = tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ErrorIncrease && c.ErrorId.HasValue && c.ErrorId.Value == error.Id).Sum(c => c.ThanhPham);
                                                        quantities -= tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ErrorReduce && c.ErrorId.HasValue && c.ErrorId.Value == error.Id).Sum(c => c.ThanhPham);
                                                        listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductError + "," + listStrSetSanLuong[i] + "," + (quantities < 0 ? 0 : quantities) + "," + error.Code);
                                                    }
                                                }

                                                switch (kp_Obj.TypeOfKeypad)
                                                {
                                                case (int)eTypeOfKeypad.All:
                                                    quantities  = tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductIncrease && c.ProductOutputTypeId == (int)eProductOutputType.KCS).Sum(c => c.ThanhPham);
                                                    quantities -= tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductReduce && c.ProductOutputTypeId == (int)eProductOutputType.KCS).Sum(c => c.ThanhPham);
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + listStrSetSanLuong[i] + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.KCS);

                                                    quantities  = tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductIncrease && c.ProductOutputTypeId == (int)eProductOutputType.TC).Sum(c => c.ThanhPham);
                                                    quantities -= tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductReduce && c.ProductOutputTypeId == (int)eProductOutputType.TC).Sum(c => c.ThanhPham);
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + listStrSetSanLuong[i] + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.TC);

                                                    quantities  = btps.Where(c => c.CommandTypeId == (int)eCommandRecive.BTPIncrease).Sum(c => c.BTPNgay);
                                                    quantities -= btps.Where(c => c.CommandTypeId == (int)eCommandRecive.BTPReduce).Sum(c => c.BTPNgay);
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + listStrSetSanLuong[i] + "," + (quantities < 0 ? 0 : quantities) + ",,");
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + listStrSetSanLuong[i] + "," + 0 + ",1");
                                                    break;

                                                case (int)eTypeOfKeypad.KCS:
                                                    quantities  = tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductIncrease && c.ProductOutputTypeId == (int)eProductOutputType.KCS).Sum(c => c.ThanhPham);
                                                    quantities -= tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductReduce && c.ProductOutputTypeId == (int)eProductOutputType.KCS).Sum(c => c.ThanhPham);
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + listStrSetSanLuong[i] + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.KCS);
                                                    break;

                                                case (int)eTypeOfKeypad.TC:
                                                    quantities  = tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductIncrease && c.ProductOutputTypeId == (int)eProductOutputType.TC).Sum(c => c.ThanhPham);
                                                    quantities -= tdns.Where(c => c.CommandTypeId == (int)eCommandRecive.ProductReduce && c.ProductOutputTypeId == (int)eProductOutputType.TC).Sum(c => c.ThanhPham);
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeProductQuantity + "," + listStrSetSanLuong[i] + "," + (quantities < 0 ? 0 : quantities) + "," + (int)eProductOutputType.TC);
                                                    break;

                                                case (int)eTypeOfKeypad.BTP:
                                                    quantities  = 0;
                                                    quantities  = btps.Where(c => c.CommandTypeId == (int)eCommandRecive.BTPIncrease).Sum(c => c.BTPNgay);
                                                    quantities -= btps.Where(c => c.CommandTypeId == (int)eCommandRecive.BTPReduce).Sum(c => c.BTPNgay);
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + listStrSetSanLuong[i] + "," + (quantities < 0 ? 0 : quantities) + ",,");
                                                    listStrProductConfig.Add(kp_Obj.EquipmentId.ToString() + "," + (int)eCommandSend.ChangeBTPQuantities + "," + listStrSetSanLuong[i] + "," + 0 + ",1");

                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(strListChuyen) && listMapIdSanPhamNgay.Count > 0)
                {
                    #region
                    var resultAdd = BLLMapCommoIdForDay.AddMapIdSanPhamNgay(strListChuyen.Substring(0, strListChuyen.Length - 1).Split(',').Select(x => Convert.ToInt32(x)).ToList(), listMapIdSanPhamNgay);;
                    if (resultAdd)
                    {
                        if (listStrProductConfig.Count > 0)
                        {
                            frmMainNew.listDataSendKeyPad.AddRange(listStrProductConfig);
                        }

                        if (frmMainNew.listMapIdSanPhamNgay != null)
                        {
                            var olds = frmMainNew.listMapIdSanPhamNgay.Where(x => x.MaChuyen == lineId).ToList();
                            if (olds.Count > 0)
                            {
                                foreach (var item in olds)
                                {
                                    frmMainNew.listMapIdSanPhamNgay.Remove(item);
                                }
                            }
                        }
                        else if (frmMainNew.listMapIdSanPhamNgay == null)
                        {
                            frmMainNew.listMapIdSanPhamNgay = new List <PMS.Data.MapIdSanPhamNgay>();
                        }
                        frmMainNew.listMapIdSanPhamNgay.AddRange(listMapIdSanPhamNgay);

                        // Reset lai thong tin ngay ve 0
                        if (IsResetAllToZero)
                        {
                            BLLProductivity.ResetDayInforByDate(DateTime.Now, assigns.Select(x => x.STTCHuyen_SanPham).ToList(), frmMainNew.getBTPInLineByType);
                        }
                        return(true);
                    }
                    #endregion
                }
            }
            catch (Exception)
            { }
            return(false);
        }