Exemplo n.º 1
0
        private ImportMessageModel BarcodeInfo_FormatRow(DataRow row, Mes_Tra_SourceBarcode itemObj, int rowIndex)
        {
            ImportMessageModel errorObj = null;

            try
            {
                itemObj.Barcode = TConvertHelper.FormatDBString(row["条码"]);
                if (string.IsNullOrEmpty(itemObj.Barcode))
                {
                    return(new ImportMessageModel()
                    {
                        RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = "条码不能为空"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ImportMessageModel()
                {
                    RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = ex.Message
                });
            }

            return(errorObj);
        }
Exemplo n.º 2
0
        public List <Mes_Tra_SourceBarcode> FindByPage(Mes_Tra_SourceBarcode obj, ref PagerBase pager)
        {
            string sql = @"SELECT T1.* FROM Mes_Tra_SourceBarcode T1 WITH(NOLOCK) WHERE 1=1 ";

            if (!string.IsNullOrEmpty(obj.Barcode))
            {
                sql += string.Format(" AND T1.Barcode Like '{0}%'", obj.Barcode);
            }
            if (!string.IsNullOrEmpty(obj.PackSN))
            {
                sql += string.Format(" AND T1.PackSN Like '{0}%'", obj.PackSN);
            }
            if (!string.IsNullOrEmpty(obj.CreatedTimeStart))
            {
                sql += string.Format(" AND T1.CreatedTime >='{0}'", obj.CreatedTimeStart);
            }
            if (!string.IsNullOrEmpty(obj.CreatedTimeEnd))
            {
                sql += string.Format(" AND T1.CreatedTime <'{0}'", TConvertHelper.FormatDBDate(obj.CreatedTimeEnd).AddDays(1));
            }

            string orderBy = pager.OrderBy;

            if (string.IsNullOrEmpty(orderBy))
            {
                orderBy = "CreatedTime DESC";
            }
            string cmdPageSql  = string.Format(BaseDao.PageSql, orderBy, sql, pager.StartNo, pager.EndNo);
            string cmdCountSql = string.Format(BaseDao.CountSql, sql.Substring(sql.ToLower().IndexOf("from", StringComparison.Ordinal)));

            //查询总记录数
            pager.TotalItemCount = this.CurDbSession.FromSql(cmdCountSql).ToScalar <int>();
            //返回当前页的记录数
            return(this.CurDbSession.FromSql(cmdPageSql).ToList <Mes_Tra_SourceBarcode>());
        }
Exemplo n.º 3
0
        public ActionResult BarcodeInfo_FindByPage(Mes_Tra_SourceBarcode obj, int page, int rows)
        {
            var pager = new PagerBase()
            {
                CurrentPageIndex = page, PageSize = rows
            };
            var list = SourceBarcodeDao.Instance.FindByPage(obj, ref pager);

            return(Json(new { total = pager.TotalItemCount, rows = list }));
        }
Exemplo n.º 4
0
        private IList <ImportMessageModel> Import_BarcodeInfo(DataTable dtData)
        {
            IList <ImportMessageModel> resultList = new List <ImportMessageModel>();
            //提示用户导入消息有错,但不影响数据导入
            IList <ImportMessageModel>   msgList  = new List <ImportMessageModel>();
            List <Mes_Tra_SourceBarcode> dataList = new List <Mes_Tra_SourceBarcode>();
            int                rowIndex           = 0;//第1行是行头
            DateTime           time     = DateTime.Now;
            ImportMessageModel errorObj = null;
            string             batchNo  = DateTime.Now.ToString("yyMMddHHmmss");

            if (dtData != null && dtData.Rows.Count > 0)
            {
                Mes_Tra_SourceBarcode itemObj = null;
                foreach (DataRow row in dtData.Rows)
                {
                    rowIndex++;
                    itemObj             = new Mes_Tra_SourceBarcode();
                    itemObj.CreatedTime = time;
                    itemObj.Creater     = curUserId;
                    itemObj.PackSN      = batchNo;
                    //存样品信息
                    errorObj = BarcodeInfo_FormatRow(row, itemObj, rowIndex);
                    if (errorObj != null) //记录行错误信息
                    {
                        resultList.Add(errorObj);
                        continue;
                    }

                    //检测条码是否重复
                    if (SourceBarcodeDao.Instance.IsExist(itemObj.Barcode))
                    {
                        resultList.Add(new ImportMessageModel()
                        {
                            RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = string.Format("条码【{0}】已经存在", itemObj.Barcode)
                        });
                    }
                    if (dataList.Exists(p => p.Barcode == itemObj.Barcode))
                    {
                        resultList.Add(new ImportMessageModel()
                        {
                            RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = string.Format("条码【{0}】重复导入", itemObj.Barcode)
                        });
                    }

                    dataList.Add(itemObj);
                }
            }


            //如果校验有错误,直接返回错误信息
            if (resultList.Count > 0)
            {
                return(resultList);
            }
            //2.校验成功执行导入
            SourceBarcodeDao.Instance.Import(dataList, resultList);
            if (resultList.Count == 0)
            {
                resultList.Add(new ImportMessageModel {
                    RowData = "导入成功", RowMessage = "数据已成功导入"
                });
            }

            return(resultList);
        }