예제 #1
0
        public MaterialUnloading GetMaterialUnloading(string unloadingNo)
        {
            MaterialUnloading obj = new MaterialUnloading();

            using (MaterialUnloadingServiceClient client = new MaterialUnloadingServiceClient())
            {
                MethodReturnResult <MaterialUnloading> result = client.Get(unloadingNo);
                if (result.Code <= 0 && result.Data != null)
                {
                    obj = result.Data;
                }
            }
            return(obj);
        }
예제 #2
0
        public async Task <ActionResult> Save(MaterialUnloadingViewModel model)
        {
            MethodReturnResult rst = new MethodReturnResult();

            try
            {
                using (MaterialUnloadingServiceClient client = new MaterialUnloadingServiceClient())
                {
                    //创建下料号
                    if (string.IsNullOrEmpty(model.UnloadingNo.ToUpper()))
                    {
                        model.UnloadingNo = Convert.ToString(Guid.NewGuid());
                    }

                    MaterialUnloading obj = new MaterialUnloading()
                    {
                        Key = model.UnloadingNo.ToUpper(),
                        RouteOperationName = model.RouteOperationName,
                        ProductionLineCode = model.ProductionLineCode,
                        EquipmentCode      = model.EquipmentCode,
                        Operator           = model.Operator,
                        UnloadingTime      = model.UnloadingTime,
                        Description        = model.Description,
                        Editor             = User.Identity.Name,
                        Creator            = User.Identity.Name
                    };

                    char splitChar      = ',';
                    var  ItemNos        = Request["ItemNo"].Split(splitChar);
                    var  LineStoreNames = Request["LineStoreName"].Split(splitChar);
                    var  MaterialCodes  = Request["MaterialCode"].Split(splitChar);
                    var  MaterialLots   = Request["MaterialLot"].Split(splitChar);
                    var  Qtys           = Request["UnloadingQty"].Split(splitChar);
                    var  LoadingKeys    = Request["LoadingNo"].Split(splitChar);
                    var  LoadingItemNos = Request["LoadingItemNo"].Split(splitChar);

                    List <MaterialUnloadingDetail> lst = new List <MaterialUnloadingDetail>();
                    for (int i = 0; i < ItemNos.Length; i++)
                    {
                        lst.Add(new MaterialUnloadingDetail()
                        {
                            Key = new MaterialUnloadingDetailKey()
                            {
                                UnloadingKey = obj.Key,
                                ItemNo       = i + 1
                            },
                            LoadingKey    = LoadingKeys[i].ToUpper(),
                            LoadingItemNo = Convert.ToInt32(LoadingItemNos[i]),
                            LineStoreName = LineStoreNames[i].ToUpper(),
                            OrderNumber   = model.OrderNumber,
                            MaterialCode  = MaterialCodes[i].ToUpper(),
                            MaterialLot   = MaterialLots[i].ToUpper(),
                            UnloadingQty  = Convert.ToDouble(Qtys[i]),
                            Editor        = User.Identity.Name,
                            Creator       = User.Identity.Name
                        });

                        if (Convert.ToDouble(Qtys[i]) == 0)
                        {
                            rst.Code    = 1008;
                            rst.Message = string.Format("物料批号({0})下料数量不能为0。"
                                                        , MaterialLots[i].ToUpper());
                            return(Json(rst));
                        }
                    }

                    rst = await client.AddAsync(obj, lst);

                    if (rst.Code == 0)
                    {
                        rst.Message = string.Format(LSMResources.StringResource.MaterialUnloading_Save_Success
                                                    , obj.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                rst.Code    = 1000;
                rst.Message = ex.Message;
                rst.Detail  = ex.ToString();
            }
            return(Json(rst));
        }
예제 #3
0
        public async Task <ActionResult> ExportToExcel(MaterialUnloadingDetailQueryViewModel model)
        {
            IList <MaterialUnloadingDetail> lst = new List <MaterialUnloadingDetail>();

            using (MaterialUnloadingServiceClient client = new MaterialUnloadingServiceClient())
            {
                await Task.Run(() =>
                {
                    PagingConfig cfg = new PagingConfig()
                    {
                        IsPaging = false,
                        OrderBy  = "CreateTime Desc,Key.UnloadingKey,Key.ItemNo",
                        Where    = GetWhereCondition(model)
                    };
                    MethodReturnResult <IList <MaterialUnloadingDetail> > result = client.GetDetail(ref cfg);

                    if (result.Code == 0)
                    {
                        lst = result.Data;
                    }
                });
            }
            //创建工作薄。
            IWorkbook wb = new HSSFWorkbook();
            //设置EXCEL格式
            ICellStyle style = wb.CreateCellStyle();

            style.FillForegroundColor = 10;
            //有边框
            style.BorderBottom = BorderStyle.Thin;
            style.BorderLeft   = BorderStyle.Thin;
            style.BorderRight  = BorderStyle.Thin;
            style.BorderTop    = BorderStyle.Thin;
            IFont font = wb.CreateFont();

            font.Boldweight = 10;
            style.SetFont(font);
            ICell  cell = null;
            IRow   row  = null;
            ISheet ws   = null;

            for (int j = 0; j < lst.Count; j++)
            {
                if (j % 65535 == 0)
                {
                    ws  = wb.CreateSheet();
                    row = ws.CreateRow(0);
                    #region //列名
                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingViewModel_UnloadingNo);  //下料号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingDetailViewModel_ItemNo);  //项目号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingViewModel_RouteOperationName);  //工序

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingViewModel_ProductionLineCode);  //生产线

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingViewModel_EquipmentCode);  //设备



                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingViewModel_OrderNumber);  //工单号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingDetailViewModel_MaterialCode);  //物料编码

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("物料名称");  //物料名称

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingDetailViewModel_MaterialLot);  //物料批号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingDetailViewModel_UnloadingQty);  //下料数量

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("下料日期");  //下料时间

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingViewModel_UnloadingTime);  //下料时间

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingViewModel_Operator);  //操作人

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingDetailViewModel_LoadingNo);  //对应上料号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingDetailViewModel_LoadingItemNo);  //对应上料项目号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(LSMResources.StringResource.MaterialUnloadingDetailViewModel_LineStoreName);  //线边仓

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("编辑人");  //编辑人

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("编辑时间");  //编辑时间
                    #endregion
                    font.Boldweight = 5;
                }

                MaterialUnloadingDetail obj = lst[j];
                MaterialUnloading       objMaterialUnloading = model.GetMaterialUnloading(obj.Key.UnloadingKey);
                Material m = model.GetMaterial(obj.MaterialCode);
                row = ws.CreateRow(j + 1);

                #region //数据
                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.Key.UnloadingKey);  //下料号

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.Key.ItemNo);  //项目号

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(objMaterialUnloading.RouteOperationName);  //工序

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(objMaterialUnloading.ProductionLineCode);  //生产线

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(objMaterialUnloading.EquipmentCode);  //设备



                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.OrderNumber);  //工单号

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.MaterialCode);  //物料编码

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(m == null ? string.Empty : m.Name);  //物料名称

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.MaterialLot);  //物料批号

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.UnloadingQty);  //下料数量

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(string.Format("{0:yyyy-MM-dd}", objMaterialUnloading.UnloadingTime));  //下料日期

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", objMaterialUnloading.UnloadingTime));  //下料时间

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(objMaterialUnloading.Operator);  //操作人

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(@obj.LoadingKey);  //对应上料号

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.LoadingItemNo);  //对应上料项目号

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.LineStoreName);  //线边仓

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(obj.Editor);  //编辑人

                cell           = row.CreateCell(row.Cells.Count);
                cell.CellStyle = style;
                cell.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", obj.EditTime));  //编辑时间
                #endregion
            }

            MemoryStream ms = new MemoryStream();
            wb.Write(ms);
            ms.Flush();
            ms.Position = 0;
            return(File(ms, "application/vnd.ms-excel", "MaterialUnloadingData.xls"));
        }