Beispiel #1
0
    void UCFileUpload1_OnUpload(object sender, EventArgs e)
    {
        UploadEventArgs ue = e as UploadEventArgs;
        DataTable       dtSGMStocktakeItem = ue.ContentTable;

        dtSGMStocktakeItem.Columns["序号"].ColumnName    = "RowNumber";
        dtSGMStocktakeItem.Columns["零件号"].ColumnName   = "PartNo";
        dtSGMStocktakeItem.Columns["工厂"].ColumnName    = "Plant";
        dtSGMStocktakeItem.Columns["库位"].ColumnName    = "Store";
        dtSGMStocktakeItem.Columns["线旁"].ColumnName    = "Line";
        dtSGMStocktakeItem.Columns["加工区"].ColumnName   = "Machining";
        dtSGMStocktakeItem.Columns["存储区域"].ColumnName  = "SLOC";
        dtSGMStocktakeItem.Columns["起始CSN"].ColumnName = "StartCSN";
        dtSGMStocktakeItem.Columns["终止CSN"].ColumnName = "EndCSN";
        dtSGMStocktakeItem.DefaultView.Sort            = "PartNo";
        dtSGMStocktakeItem = dtSGMStocktakeItem.DefaultView.ToTable();

        StocktakeNotification notification = Service.GetNotification(new StocktakeNotification {
            NotificationID = long.Parse(NotiID)
        });
        List <View_StocktakeResult> items = new List <View_StocktakeResult>();
        int           userID   = CurrentUser.UserInfo.UserID;
        List <string> errorMsg = new List <string>();
        List <View_StocktakeResult> itemList = new List <View_StocktakeResult>();
        bool hasError = false;

        for (int i = 0; i < dtSGMStocktakeItem.Rows.Count; i++)
        {
            DataRow       row       = dtSGMStocktakeItem.Rows[i];
            string        partNo    = row["PartNo"].ToString();
            string        plantCode = row["Plant"].ToString();
            string        duns      = row["DUNS"].ToString();
            string        sloc      = row["SLOC"].ToString();
            StoreLocation location  = this.StoreLocations.Find(l => l.LogisticsSysSLOC == sloc);
            if (location == null)
            {
                string msg = string.Format("存储区域【{0}】不存在", sloc);// i + 2);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
                continue;
            }


            if (i % 1000 == 0)
            {
                string startCode = partNo;
                int    end       = i + 999;
                if (end >= dtSGMStocktakeItem.Rows.Count)
                {
                    end = dtSGMStocktakeItem.Rows.Count - 1;
                }
                string endCode = dtSGMStocktakeItem.Rows[end]["PartNo"].ToString();
                items = Service.GetStocktakeResultOfScope(new View_StocktakeResult {
                    NotificationID = notification.NotificationID
                }, startCode, endCode);
            }

            View_StocktakeResult result = null;
            if (result == null)
            {
                result = items.Find(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && r.SGMLocationID != null && r.SGMLocationID == location.LocationID);// && r.SGMItemID != null);
            }
            if (result == null)
            {
                result = items.Find(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && r.RepairLocationID != null && r.RepairLocationID == location.LocationID);//&& r.RepairItemID != null);
            }
            if (result == null)
            {
                result = items.Find(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && r.CSMTLocationID != null && r.CSMTLocationID == location.LocationID);//&& r.CSMTItemID != null);
            }
            if (result == null)
            {
                result = items.Find(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && r.GeneralItemID != null && r.GeneralItemID == location.LocationID);//&& r.CSMTItemID != null);
            }
            if (result == null)
            {
                result = items.FirstOrDefault(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && r.RDCLocationID != null && r.RDCLocationID == location.LocationID);//&& r.RDCItemID != null);
            }
            if (result == null)
            {
                string msg = string.Format("工厂【{0}】,DUNS【{1}】,存储区域为【{2}】的零件【{3}】不在盘点通知单中", plantCode, duns, sloc, partNo);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                string csmtDUNS = CurrentUser.UserInfo.ConsignmentDUNS;
                View_StocktakeResult result1 = null;
                result1 = items.Find(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && r.CSMTLocationID != null && r.CSMTLocationID == location.LocationID);
                if (string.IsNullOrEmpty(csmtDUNS) && (result1 != null))
                {
                    string msg = string.Format("当前用户无权导入工厂【{0}】,DUNS【{1}】,存储区域为【{2}】的零件【{3}】", plantCode, duns, sloc, partNo);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }
                if (!string.IsNullOrEmpty(csmtDUNS) && !items.Exists(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && string.Equals(r.CSMTDUNS, csmtDUNS)))
                {
                    string msg = string.Format("当前用户无权导入工厂【{0}】,DUNS【{1}】,存储区域为【{2}】的零件【{3}】", plantCode, duns, sloc, partNo);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }
                View_StocktakeResult result2 = null;
                result2 = items.Find(r => r.PartCode == partNo && r.PartPlantCode == plantCode && r.DUNS == duns && r.SGMLocationID != null && r.SGMLocationID == location.LocationID);
                if ((CurrentUser.UserInfo.Workshop == null) && (result2 != null))
                {
                    string msg = string.Format("当前用户无权导入当前车间,工厂【{0}】,DUNS【{1}】,存储区域为【{2}】的零件【{3}】的实盘结果", plantCode, duns, sloc, partNo);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }
                if (!hasError)
                {
                    decimal?available = SGM.Common.Utility.Utils.GetDecimalDbCell(row["Available"]);
                    decimal?qi        = SGM.Common.Utility.Utils.GetDecimalDbCell(row["QI"]);
                    decimal?block     = SGM.Common.Utility.Utils.GetDecimalDbCell(row["Block"]);

                    WorkshopStocktakeDetail detail = null;

                    if (CurrentUser.UserInfo.Workshop != null)
                    {
                        detail =
                            result.WorkshopDetails.FirstOrDefault(d => d.WorkshopCode == CurrentUser.UserInfo.Workshop.WorkshopCode);
                    }

                    if (result.SGMItemID != null && result.SGMLocationID == location.LocationID && CurrentUser.UserInfo.Workshop != null && detail != null)
                    {
                        for (int j = result.WorkshopDetails.Count - 1; j >= 0; j--)
                        {
                            if (result.WorkshopDetails[j].ItemDetailID != detail.ItemDetailID)
                            {
                                result.WorkshopDetails.RemoveAt(j);
                            }
                        }
                        detail.SGMFillinBy = userID;
                        detail.SGMBlock    = block;
                        detail.SGMQI       = qi;
                        detail.Line        = SGM.Common.Utility.Utils.GetDecimalDbCell(row["Line"]);
                        detail.Machining   = SGM.Common.Utility.Utils.GetDecimalDbCell(row["Machining"]);
                        detail.Store       = SGM.Common.Utility.Utils.GetDecimalDbCell(row["Store"]);
                        if (row["StartCSN"] != DBNull.Value && row["StartCSN"] + "" != string.Empty)
                        {
                            detail.StartCSN = row["StartCSN"].ToString();
                        }
                        if (row["EndCSN"] != DBNull.Value && row["EndCSN"] + "" != string.Empty)
                        {
                            detail.EndCSN = row["EndCSN"].ToString();
                        }
                    }
                    else
                    {
                        if (result.CSMTItemID != null && result.CSMTLocationID == location.LocationID)
                        {
                            result.CSMTFillinBy  = userID;
                            result.CSMTAvailable = available;
                            result.CSMTBlock     = block;
                            result.CSMTQI        = qi;
                        }
                        else
                        {
                            if (result.RepairItemID != null && result.RepairLocationID == location.LocationID)
                            {
                                result.RepairFillinBy  = userID;
                                result.RepairAvailable = available;
                                result.RepairBlock     = block;
                                result.RepairQI        = qi;
                            }
                            else
                            {
                                if (result.GeneralItemID != null && result.GenerLocationID == location.LocationID)
                                {
                                    result.GenFillinBy      = userID;
                                    result.GeneralAvailable = available;
                                    result.GeneralBlock     = block;
                                    result.GeneralQI        = qi;
                                }
                                else
                                {
                                    if (result.RDCItemID != DefaultValue.LONG && result.RDCLocationID == location.LocationID)
                                    {
                                        result.RDCFillinBy  = userID;
                                        result.RDCAvailable = available;
                                        result.RDCBlock     = block;
                                        result.RDCQI        = qi;
                                    }
                                }
                            }
                        }
                    }
                    //result.SGMBlock = int.Parse(dtSGMStocktakeItem.Rows[i]["Block"].ToString());

                    itemList.Add(result);
                }
            }
        }
        if (!hasError)
        {
            //List<View_StocktakeResult> tmpList = new List<View_StocktakeResult>();
            //string cacheKey = string.Empty;
            //while (itemList.Count > 0)
            //{
            //    tmpList.Clear();
            //    tmpList.AddRange(itemList.Take((itemList.Count < 20) ? itemList.Count : 20));
            //    itemList.RemoveRange(0, (itemList.Count < 20) ? itemList.Count : 20);
            //    if (itemList.Count > 0)
            //    {
            //        cacheKey = Service.ImportResult(notification, tmpList, cacheKey, false);
            //    }
            //    else
            //    {
            //        Service.ImportResult(notification, tmpList, cacheKey, true);
            //    }
            //    //fill in items
            //}
            Service.FillStocktakeResult(notification, itemList);
            BindDataControl(gvItems, dtSGMStocktakeItem);
            //show information
            this.UCFileUpload1.AddSuccessInfo("上传文件成功", string.Empty, string.Empty);
        }
    }
Beispiel #2
0
    void UCFileUpload1_OnUpload(object sender, EventArgs e)
    {
        UploadEventArgs ue = e as UploadEventArgs;
        DataTable       dtPartConsignment = ue.ContentTable;

        dtPartConsignment.Columns["序号"].ColumnName        = "RowNumber";
        dtPartConsignment.Columns["工厂"].ColumnName        = "PlantCode";
        dtPartConsignment.Columns["外协零件号"].ColumnName     = "PartCode";
        dtPartConsignment.Columns["供应商DUNS"].ColumnName   = "DUNS";
        dtPartConsignment.Columns["外协供应商DUNS"].ColumnName = "CDUNS";
        dtPartConsignment.Columns["外协供应商名称"].ColumnName   = "SupplierName";
        dtPartConsignment.Columns["电话"].ColumnName        = "Telephone";
        dtPartConsignment.Columns["传真"].ColumnName        = "Fax";

        bool hasError = false;
        List <View_ConsignmentPart> partlist = new List <View_ConsignmentPart>();

        for (int i = 0; i < dtPartConsignment.Rows.Count; i++)
        {
            View_ConsignmentPart partCRecord = new View_ConsignmentPart();

            Supplier supplier = this.Suppliers.SingleOrDefault(s => string.Equals(s.DUNS, dtPartConsignment.Rows[i]["CDUNS"].ToString().Trim()));
            if (supplier == null)
            {
                string msg = string.Format("第{0}行,该外协供应商DUNS不存在", i + 2);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                partCRecord.ConsignmentSupplier = supplier.SupplierID;
            }

            Part            part = new Part();
            List <ViewPart> list = new List <ViewPart>();
            part.PartCode        = dtPartConsignment.Rows[i]["PartCode"].ToString();
            part.Plant           = new Plant();
            part.Plant.PlantCode = dtPartConsignment.Rows[i]["PlantCode"] + "";
            part.Supplier        = new Supplier();
            part.Supplier.DUNS   = dtPartConsignment.Rows[i]["DUNS"] + "";

            list = this.Service.QueryParts(part);
            if (list.Count <= 0)
            {
                string msg = string.Format("第{0}行,该零件不存在", i + 2);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                partCRecord.PartID   = list[0].PartID;
                partCRecord.PartCode = dtPartConsignment.Rows[i]["PartCode"].ToString();
                partCRecord.DUNS     = dtPartConsignment.Rows[i]["DUNS"].ToString();

                partlist.Add(partCRecord);
            }
        }
        if (!hasError)
        {
            Service.ImportConsignmentRecord(partlist);
            BindDataControl(gvConsignmentPartRecord, dtPartConsignment);
            this.UCFileUpload1.AddSuccessInfo("上传文件成功", string.Empty, string.Empty);
        }
    }
Beispiel #3
0
    void UCFileUpload1_OnUpload(object sender, EventArgs e)
    {
        UploadEventArgs ue = e as UploadEventArgs;
        DataTable       dtStorelocaiton = ue.ContentTable;

        dtStorelocaiton.Columns["序号"].ColumnName        = "No";
        dtStorelocaiton.Columns["存储区域名称"].ColumnName    = "LocationName";
        dtStorelocaiton.Columns["区域类型"].ColumnName      = "TypeID";
        dtStorelocaiton.Columns["Available"].ColumnName = "Available";
        dtStorelocaiton.Columns["QI"].ColumnName        = "QI";
        dtStorelocaiton.Columns["Block"].ColumnName     = "Block";
        dtStorelocaiton.Columns["物流系统存储区域"].ColumnName  = "LogisticsSysSLOC";

        bool hasError = false;
        List <S_StoreLocation> recordList = new List <S_StoreLocation>();

        for (int i = 0; i < dtStorelocaiton.Rows.Count; i++)
        {
            S_StoreLocation storeloc = new S_StoreLocation();
            if (dtStorelocaiton.Rows[i]["LocationName"] != DBNull.Value)
            {
                storeloc.LocationName = dtStorelocaiton.Rows[i]["LocationName"].ToString();
            }

            if (dtStorelocaiton.Rows[i]["TypeID"] != DBNull.Value)
            {
                storeloc.TypeID = Convert.ToInt32(dtStorelocaiton.Rows[i]["TypeID"]);
            }

            if (dtStorelocaiton.Rows[i]["Available"] != DBNull.Value)
            {
                storeloc.AvailableIncluded = Convert.ToInt32(dtStorelocaiton.Rows[i]["Available"]);
            }

            if (dtStorelocaiton.Rows[i]["QI"] != DBNull.Value)
            {
                storeloc.QIIncluded = Convert.ToInt32(dtStorelocaiton.Rows[i]["QI"]);
            }

            if (dtStorelocaiton.Rows[i]["Block"] != DBNull.Value)
            {
                storeloc.BlockIncluded = Convert.ToInt32(dtStorelocaiton.Rows[i]["Block"]);
            }

            if (dtStorelocaiton.Rows[i]["LogisticsSysSLOC"] != DBNull.Value)
            {
                storeloc.LogisticsSysSLOC = dtStorelocaiton.Rows[i]["LogisticsSysSLOC"].ToString();
                StoreLocation store = this.StoreLocations.SingleOrDefault(s => string.Equals(s.LogisticsSysSLOC, storeloc.LogisticsSysSLOC));
                CacheHelper.RemoveCache(Consts.CACHE_KEY_STORE_LOCATION);
                if (store != null)
                {
                    string msg = string.Format("第{0}行,该物流系统存储区域已存在", i + 2);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }
            }
            if (!recordList.Exists(r => r.LocationName == storeloc.LocationName && r.LogisticsSysSLOC == storeloc.LogisticsSysSLOC))
            {
                recordList.Add(storeloc);
            }
            else
            {
                string msg = string.Format("存储区域名称{0},物流系统存储区域{1}重复", storeloc.LocationName, storeloc.LogisticsSysSLOC);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
        }

        if (!hasError)
        {
            Service.ImportStoreLocation(recordList);
            BindDataControl(gvStorelocation, dtStorelocaiton);

            this.UCFileUpload1.AddSuccessInfo("上传文件成功", string.Empty, string.Empty);
        }
    }
Beispiel #4
0
    void UCFileUpload1_OnUpload(object sender, EventArgs e)
    {
        UploadEventArgs ue           = e as UploadEventArgs;
        DataTable       dtAdjustment = ue.ContentTable;

        dtAdjustment.Columns["通知单号"].ColumnName         = "NotificationNo";
        dtAdjustment.Columns["零件号"].ColumnName          = "PartNo";
        dtAdjustment.Columns["工厂代码"].ColumnName         = "PlantNo";
        dtAdjustment.Columns["供应商DUNS"].ColumnName      = "DUNS";
        dtAdjustment.Columns["SAP存储区域代码"].ColumnName    = "SLOCID";
        dtAdjustment.Columns["Available调整值"].ColumnName = "AvailableAdjust";
        dtAdjustment.Columns["QI调整值"].ColumnName        = "QIAdjust";
        dtAdjustment.Columns["Block调整值"].ColumnName     = "BlockAdjust";

        //StocktakeNotification notification = Service.GetNotification(new StocktakeNotification { NotificationCode = long.Parse(NotiID) });
        //List<View_StocktakeResult> items = Service.GetStocktakeResult(new View_StocktakeResult { NotificationID = notification.NotificationID });

        List <string> errorMsg = new List <string>();
        //List<View_StocktakeResult> itemList = new List<View_StocktakeResult>();

        bool hasError = false;
        List <View_StocktakeItem> list = new List <View_StocktakeItem>();

        for (int i = 0; i < dtAdjustment.Rows.Count; i++)
        {
            DataRow row            = dtAdjustment.Rows[i];
            string  partNo         = row["PartNo"].ToString();
            string  plantNo        = row["PlantNo"].ToString();
            string  duns           = row["DUNS"].ToString();
            string  notificationNo = row["NotificationNo"].ToString();
            string  sloc           = row["SLOCID"].ToString();

            StoreLocation location = this.StoreLocations.Find(s => string.Equals(s.LogisticsSysSLOC, sloc));
            if (location == null)
            {
                string msg = string.Format("第{0}行存储区域不存在", i + 2);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                List <View_StocktakeItem> items = Service.QueryStocktakeItem(
                    new View_StocktakeItem
                {
                    PartCode         = partNo,
                    PartPlantCode    = plantNo,
                    DUNS             = duns,
                    LogisticsSysSLOC = sloc,
                    NotificationCode = notificationNo
                });

                if (items == null || items.Count == 0)
                {
                    string msg = string.Format("第{0}行零件不在盘点通知单中", i + 2);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }
                else
                {
                    items[0].AvailableAdjust = (row["AvailableAdjust"] == DBNull.Value) ? 0 : Convert.ToInt32(row["AvailableAdjust"]);
                    items[0].QIAdjust        = (row["QIAdjust"] == DBNull.Value) ? 0 : Convert.ToInt32(row["QIAdjust"]);
                    items[0].BlockAdjust     = (row["BlockAdjust"] == DBNull.Value) ? 0 : Convert.ToInt32(row["BlockAdjust"]);
                    list.Add(items[0]);
                }
            }
        }
        if (!hasError)
        {
            Service.ImportAdjustment(list);
            BindDataControl(gvItems, dtAdjustment);
            //show information
            this.UCFileUpload1.AddSuccessInfo("上传文件成功", string.Empty, string.Empty);
        }
    }
Beispiel #5
0
    void UCFileUpload1_OnUpload(object sender, EventArgs e)
    {
        string noticeNo = txtNoticeNo.Text.Trim();

        if (string.IsNullOrEmpty(noticeNo))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "selectNotiMsg", "alert('请选择通知单');", true);
            return;
        }

        UploadEventArgs ue        = e as UploadEventArgs;
        DataTable       dtStorage = ue.ContentTable;

        dtStorage.Columns["序号"].ColumnName          = "No";
        dtStorage.Columns["零件号"].ColumnName         = "PartNo";
        dtStorage.Columns["工厂代码"].ColumnName        = "PlantCode";
        dtStorage.Columns["物流系统存储区域"].ColumnName    = "StoreLocation";
        dtStorage.Columns["系统Available"].ColumnName = "Available";
        dtStorage.Columns["系统QI"].ColumnName        = "QI";
        dtStorage.Columns["系统Block"].ColumnName     = "Block";
        dtStorage.Columns["单价"].ColumnName          = "Price";

        bool hasError = false;
        List <S_StorageRecord>       recordList       = new List <S_StorageRecord>();
        List <ViewPart>              partList         = new List <ViewPart>();
        List <View_StocktakeDetails> stocktakeDetails = new List <View_StocktakeDetails>();

        dtStorage.DefaultView.Sort = "PartNo";
        dtStorage = dtStorage.DefaultView.ToTable();
        //get part by code, plant
        List <StorageRecordView> storageRecords = new List <StorageRecordView>();

        for (int i = 0; i < dtStorage.Rows.Count; i++)
        {
            StorageRecordView record = new StorageRecordView
            {
                PartCode  = dtStorage.Rows[i]["PartNo"].ToString(),
                PlantCode = dtStorage.Rows[i]["PlantCode"].ToString(),
                SLOC      = dtStorage.Rows[i]["StoreLocation"].ToString()
            };
            if (!storageRecords.Exists(r => r.PartCode == record.PartCode && r.PlantCode == record.PlantCode && r.SLOC == record.SLOC))
            {
                storageRecords.Add(record);
            }
            else
            {
                string msg = string.Format("库存信息零件号{0},工厂{1},存储区域{2}重复", record.PartCode, record.PlantCode, record.SLOC);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
        }
        storageRecords.Clear();
        if (!hasError)
        {
            //partList = Service.QueryPartsByCodePlant(partList);//Key(partList);
            for (int i = 0; i < dtStorage.Rows.Count; i++)
            {
                if (i % 5000 == 0)
                {
                    string startCode = dtStorage.Rows[i]["PartNo"].ToString();
                    int    end       = i + 4999;
                    if (end >= dtStorage.Rows.Count)
                    {
                        end = dtStorage.Rows.Count - 1;
                    }
                    //View_StocktakeDetails filterStocktakeDetails = new View_StocktakeDetails { NotificationCode = noticeNo };
                    string endCode = dtStorage.Rows[end]["PartNo"].ToString();
                    partList         = Service.QueryPartCodeScope(null, startCode, endCode);
                    stocktakeDetails = Service.QueryStocktakeDetailsScope(new View_StocktakeDetails {
                        NotificationCode = noticeNo
                    }, startCode, endCode);
                }
                string        sloc          = dtStorage.Rows[i]["StoreLocation"].ToString();
                StoreLocation storeLocation = this.StoreLocations.FirstOrDefault(l => l.LogisticsSysSLOC == sloc);
                if (storeLocation == null)                                //storeLocation invalid
                {
                    string msg = string.Format("物流系统存储区域【{0}】不存在", sloc); //i + 2,
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }

                View_StocktakeDetails tmpStocktakeDetails = new View_StocktakeDetails
                {
                    PartCode         = dtStorage.Rows[i]["PartNo"].ToString(),
                    NotificationCode = noticeNo
                };

                List <View_StocktakeDetails> tmpStocktakeDetailsList = stocktakeDetails.Where(s => s.NotificationCode == tmpStocktakeDetails.NotificationCode && s.PartCode == tmpStocktakeDetails.PartCode).ToList();
                //if (tmpStocktakeDetailsList == null || tmpStocktakeDetailsList.Count == 0)
                //{
                //    string msg = string.Format("通知单【{0}】中不存在零件【{1}】", tmpStocktakeDetails.NotificationCode, tmpStocktakeDetails.PartCode);
                //    UCFileUpload1.AddErrorInfo(msg);
                //    hasError = true;
                //}

                ViewPart tmpPart = new ViewPart
                {
                    PlantCode = dtStorage.Rows[i]["PlantCode"].ToString(),
                    //DUNS = dtStorage.Rows[i]["DUNS"].ToString(),
                    PartCode = dtStorage.Rows[i]["PartNo"].ToString()
                };

                //ViewPart part = partList.SingleOrDefault(p => p.PartCode == tmpPart.PartCode && p.PlantCode == tmpPart.PlantCode && p.DUNS == tmpPart.DUNS);
                List <ViewPart> tmpPartList = partList.Where(p => p.PartCode == tmpPart.PartCode && p.PlantCode == tmpPart.PlantCode).ToList();
                //if (part == null)//part is invalid
                if (tmpPartList == null || tmpPartList.Count == 0)
                {
                    //string msg = string.Format("工厂【{0}】中不存在零件【{1}】", tmpPart.PlantCode, tmpPart.PartCode);// i + 2,
                    //UCFileUpload1.AddErrorInfo(msg);
                    //hasError = true;
                }
                else
                {
                    //storeLocation is valid
                    if (storeLocation != null)
                    {
                        foreach (var part in tmpPartList)
                        {
                            S_StorageRecord tmpRecord = new S_StorageRecord
                            {
                                SLOCID = storeLocation.LocationID,
                                PartID = part.PartID
                            };

                            tmpRecord.Available = SGM.Common.Utility.Utils.GetDecimalDbCell(dtStorage.Rows[i]["Available"]);
                            tmpRecord.QI        = SGM.Common.Utility.Utils.GetDecimalDbCell(dtStorage.Rows[i]["QI"]);
                            tmpRecord.Block     = SGM.Common.Utility.Utils.GetDecimalDbCell(dtStorage.Rows[i]["Block"]);
                            tmpRecord.Price     = SGM.Common.Utility.Utils.GetDecimalDbCell(dtStorage.Rows[i]["Price"]);
                            if (tmpStocktakeDetailsList == null || tmpStocktakeDetailsList.Count == 0)
                            {
                                tmpRecord.DetailsID = 0;
                            }
                            else
                            {
                                tmpRecord.DetailsID = Convert.ToInt32(tmpStocktakeDetailsList.FirstOrDefault().DetailsID);
                                recordList.Add(tmpRecord);
                            }
                        }
                    }
                }
            }
        }



        if (!hasError)
        {
            //fill in items
            Service.ImportStorage(recordList);
            BindDataControl(gvStoreage, dtStorage);
            //show information
            this.UCFileUpload1.AddSuccessInfo("上传文件成功", string.Empty, string.Empty);
        }
    }
Beispiel #6
0
    protected void ucFileUpload_Upload(object sender, EventArgs e)
    {
        List <long> notiList = new List <long>();

        foreach (GridViewRow row in gvNotification.Rows)
        {
            if (gvNotification.DataKeys[row.RowIndex] != null)
            {
                CheckBox cbSelect = row.FindControl("cbNotiSelect") as CheckBox;
                if (cbSelect.Checked)
                {
                    long notiID = (long)gvNotification.DataKeys[row.RowIndex]["NotificationID"];
                    notiList.Add(notiID);
                }
            }
        }
        if (notiList.Count == 0)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "selectNotiMsg", "alert('请选择通知单');", true);
            return;
        }
        UploadEventArgs ue = e as UploadEventArgs;

        DataTable dtDetails = ue.ContentTable;

        dtDetails.DefaultView.Sort = "零件号";
        dtDetails = dtDetails.DefaultView.ToTable();
        bool            isValid  = true;
        List <ViewPart> partList = new List <ViewPart>();

        //get part by code, plant, duns
        for (int i = 0; i < dtDetails.Rows.Count; i++)
        {
            ViewPart tmpPart = new ViewPart
            {
                PlantCode = dtDetails.Rows[i]["工厂代码"].ToString(),
                DUNS      = dtDetails.Rows[i]["供应商DUNS"].ToString(),
                PartCode  = dtDetails.Rows[i]["零件号"].ToString()
            };
            if (!partList.Exists(p => p.PartCode == tmpPart.PartCode && p.PlantCode == tmpPart.PlantCode && p.DUNS == tmpPart.DUNS))
            {
                partList.Add(tmpPart);
            }
        }
        //partList = Service.QueryPartsByKey(partList);

        List <View_StocktakeDetails> detailsList = new List <View_StocktakeDetails>();

        for (int i = 0; i < dtDetails.Rows.Count; i++)
        {
            bool hasError = false;

            View_StocktakeDetails details = new View_StocktakeDetails
            {
                PartCode      = dtDetails.Rows[i]["零件号"].ToString(),
                DUNS          = dtDetails.Rows[i]["供应商DUNS"].ToString(),
                PartPlantCode = dtDetails.Rows[i]["工厂代码"].ToString(),
                UnRecorded    = dtDetails.Rows[i]["未入账"] + ""
            };
            details.Wip  = SGM.Common.Utility.Utils.GetDecimalDbCell(dtDetails.Rows[i]["Wip"]);
            details.M080 = SGM.Common.Utility.Utils.GetDecimalDbCell(dtDetails.Rows[i]["M080"]);

            string msg;
            if (i % 5000 == 0)
            {
                string startCode = details.PartCode;
                int    end       = i + 4999;
                if (end >= dtDetails.Rows.Count)
                {
                    end = dtDetails.Rows.Count - 1;
                }
                string endCode = dtDetails.Rows[end]["零件号"].ToString();
                partList = Service.QueryPartCodeScope(null, startCode, endCode);
            }
            ViewPart part = partList.FirstOrDefault(p => p.PartCode == details.PartCode && p.PlantCode == details.PartPlantCode && p.DUNS == details.DUNS);
            if (part == null)//part is invalid
            {
                msg = string.Format("工厂为【{0}】,供应商为【{1}】的零件【{2}】不存在", details.PartPlantCode, details.DUNS, details.PartCode);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                details.PartID = part.PartID;
            }

            if (!hasError)
            {
                if (detailsList.Exists(d => d.PartPlantCode == details.PartPlantCode && d.DUNS == details.DUNS && string.Equals(d.PartCode, details.PartCode)))
                {
                    msg = string.Format("工厂为【{0}】,供应商为【{1}】的零件【{2}】数据重复", details.PartPlantCode, details.DUNS, details.PartCode);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }
                else
                {
                    detailsList.Add(details);
                }
            }
            isValid = isValid && !hasError;
        }

        if (isValid)
        {
            Service.ImportAnalyseRef(detailsList, notiList);
            BindDataControl(gvResult, detailsList);
            //show information
            this.UCFileUpload1.AddSuccessInfo("导入成功", string.Empty, string.Empty);
        }
    }
Beispiel #7
0
    protected void ucFileUpload_Upload(object sender, EventArgs e)
    {
        UploadEventArgs ue        = e as UploadEventArgs;
        DataTable       dtDetails = ue.ContentTable;

        dtDetails.DefaultView.Sort = "零件号";
        dtDetails = dtDetails.DefaultView.ToTable();
        bool            isValid  = true;
        List <ViewPart> partList = new List <ViewPart>();

        //get part by code, plant, duns
        //for (int i = 0; i < dtDetails.Rows.Count; i++)
        //{
        //    ViewPart tmpPart = new ViewPart
        //    {
        //        PlantCode = dtDetails.Rows[i]["工厂代码"].ToString(),
        //        DUNS = dtDetails.Rows[i]["供应商DUNS"].ToString(),
        //        PartCode = dtDetails.Rows[i]["零件号"].ToString()
        //    };
        //    if (!partList.Exists(p => string.Equals(p.PartCode , tmpPart.PartCode, StringComparison.OrdinalIgnoreCase) && string.Equals(p.PlantCode ,tmpPart.PlantCode , StringComparison.OrdinalIgnoreCase)&& string.Equals(p.DUNS ,tmpPart.DUNS, StringComparison.OrdinalIgnoreCase)))
        //    {
        //        partList.Add(tmpPart);
        //    }
        //}

        List <View_StocktakeDetails> detailsList = new List <View_StocktakeDetails>();

        for (int i = 0; i < dtDetails.Rows.Count; i++)
        {
            bool hasError = false;
            View_StocktakeDetails details = new View_StocktakeDetails
            {
                RowNumber     = int.Parse(dtDetails.Rows[i]["序号"].ToString()),
                PartCode      = dtDetails.Rows[i]["零件号"].ToString(),
                DUNS          = dtDetails.Rows[i]["供应商DUNS"].ToString(),
                PartPlantCode = dtDetails.Rows[i]["工厂代码"].ToString(),
                TypeName      = dtDetails.Rows[i]["申请类别"].ToString(),
                PriorityName  = dtDetails.Rows[i]["紧急程度"].ToString(),
                Description   = dtDetails.Rows[i]["备注"].ToString()
            };
            string msg;
            if (i % 5000 == 0)
            {
                string startCode = details.PartCode;
                int    end       = i + 4999;
                if (end >= dtDetails.Rows.Count)
                {
                    end = dtDetails.Rows.Count - 1;
                }
                string endCode = dtDetails.Rows[end]["零件号"].ToString();
                partList = Service.QueryPartCodeScope(null, startCode, endCode);
            }
            ViewPart part = partList.FirstOrDefault(p => string.Equals(p.PartCode, details.PartCode, StringComparison.OrdinalIgnoreCase) && string.Equals(p.PlantCode, details.PartPlantCode, StringComparison.OrdinalIgnoreCase) && string.Equals(p.DUNS, details.DUNS, StringComparison.OrdinalIgnoreCase));
            if (part == null)//part is invalid
            {
                msg = string.Format("第{0}行,该零件不存在", i + 2);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                details.PartID = part.PartID;
            }
            StocktakePriority priority = Priorities.FirstOrDefault(p => string.Equals(p.PriorityName, details.PriorityName, StringComparison.OrdinalIgnoreCase));
            if (priority == null)
            {
                msg = string.Format("第{0}行,紧急程度信息非法", i + 2);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                details.Priority = priority.PriorityID;
            }
            StocktakeType type = StocktakeTypes.FirstOrDefault(t => string.Equals(t.TypeName, details.TypeName, StringComparison.OrdinalIgnoreCase));
            if (type == null)
            {
                msg = string.Format("第{0}行,申请类别信息非法", i + 2);
                UCFileUpload1.AddErrorInfo(msg);
                hasError = true;
            }
            else
            {
                details.StocktakeType = type.TypeID;
            }
            if (!hasError)
            {
                if (detailsList.Exists(d => string.Equals(d.TypeName, details.TypeName, StringComparison.OrdinalIgnoreCase) && string.Equals(d.PriorityName, details.PriorityName, StringComparison.OrdinalIgnoreCase) && string.Equals(d.PartPlantCode, details.PartPlantCode, StringComparison.OrdinalIgnoreCase) && string.Equals(d.DUNS, details.DUNS, StringComparison.OrdinalIgnoreCase) && string.Equals(d.PartCode, details.PartCode, StringComparison.OrdinalIgnoreCase)))
                {
                    msg = string.Format("第{0}行,数据重复", i + 2);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                }
                else
                {
                    detailsList.Add(details);
                }
            }
            isValid = isValid && !hasError;
        }

        if (isValid)
        {
            NewStocktakeRequest newRequest = new NewStocktakeRequest
            {
                IsStatic     = (rblIsStatic.SelectedIndex == 1),
                RequestBy    = CurrentUser.UserInfo.UserID,
                IsCycleCount = false,
                Details      = (from d in detailsList
                                select new NewStocktakeDetails
                {
                    PartID = d.PartID.ToString(),
                    StocktakePriority = d.Priority.Value,
                    StocktakeTypeID = d.StocktakeType.Value,
                    Description = d.Description
                }).ToList()
            };
            int currentDynAmount = 0;
            int currentStAmount  = 0;
            foreach (var item in UserGroups)
            {
                currentDynAmount += item.CurrentDynamicStocktake ?? 0;
                currentStAmount  += item.CurrentStaticStocktake ?? 0;
            }
            int maxUserCount;
            int currentCount;
            int maxCount;
            if (!newRequest.IsStatic)
            {
                BizParams param = BizParamsList.Find(p => p.ParamKey == "MaxDynamic");
                maxCount     = int.Parse(param.ParamValue);
                maxUserCount = CurrentUser.UserInfo.UserGroup.MaxDynamicStocktake ?? 0;
                currentCount = CurrentUser.UserInfo.UserGroup.CurrentDynamicStocktake.Value;
                int dynOverflowAmount = currentCount + newRequest.Details.Count - maxUserCount;
                if (dynOverflowAmount > 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过当前用户组动态盘点上限" + dynOverflowAmount + "个')", true);
                    return;
                }
                dynOverflowAmount = currentDynAmount + newRequest.Details.Count - maxCount;
                if (dynOverflowAmount > 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过动态盘点总数上限" + dynOverflowAmount + "个')", true);
                    return;
                }
            }

            if (newRequest.IsStatic)
            {
                BizParams param = BizParamsList.Find(p => p.ParamKey == "MaxStatic");
                maxCount     = int.Parse(param.ParamValue);
                maxUserCount = CurrentUser.UserInfo.UserGroup.MaxStaticStocktake.Value;

                currentCount = CurrentUser.UserInfo.UserGroup.CurrentStaticStocktake.Value;
                int stOverflowAmount = currentCount + newRequest.Details.Count - maxUserCount;
                if (stOverflowAmount > 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过当前用户组静态盘点上限" + stOverflowAmount + "个')", true);
                    return;
                }

                stOverflowAmount = currentStAmount + newRequest.Details.Count - maxCount;
                if (stOverflowAmount > 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "maxOverflow", "alert('超过静态盘点总数上限" + stOverflowAmount + "个')", true);
                    return;
                }
            }
            //fill in items
            StocktakeRequest request = Service.RequestStocktake(newRequest);
            BindDataControl(gvResult, detailsList);
            CurrentUser.RefreshUserProfile();
            CacheHelper.RemoveCache(Consts.CACHE_KEY_USER_GROUPS);
            //show information
            this.UCFileUpload1.AddSuccessInfo("盘点申请成功,申请单号" + request.RequestNumber, string.Empty, string.Empty);
        }
    }
Beispiel #8
0
    void UCFileUpload1_OnUpload(object sender, EventArgs e)
    {
        UploadEventArgs ue     = e as UploadEventArgs;
        DataTable       dtPart = ue.ContentTable;

        dtPart.Columns["序号"].ColumnName       = "RowNumber";
        dtPart.Columns["零件号"].ColumnName      = "PartCode";
        dtPart.Columns["零件名称"].ColumnName     = "PartChineseName";
        dtPart.Columns["工位"].ColumnName       = "WorkLocation";
        dtPart.Columns["库位"].ColumnName       = "Dloc";
        dtPart.Columns["循环盘点级别"].ColumnName   = "LevelName";
        dtPart.Columns["已循环盘点次数"].ColumnName  = "CycleCountTimes";
        dtPart.Columns["车型"].ColumnName       = "Specs";
        dtPart.Columns["FollowUp"].ColumnName = "Followup";
        dtPart.Columns["工厂"].ColumnName       = "PlantCode";
        dtPart.Columns["车间"].ColumnName       = "Workshops";
        dtPart.Columns["工段"].ColumnName       = "Segments";
        dtPart.Columns["物料类别"].ColumnName     = "CategoryName";
        dtPart.Columns["物料状态"].ColumnName     = "StatusName";
        dtPart.Columns["DUNS"].ColumnName     = "DUNS";

        dtPart.Columns.Add("UserName", typeof(string));
        dtPart.DefaultView.Sort = "PartCode";
        dtPart = dtPart.DefaultView.ToTable();
        bool            hasError = false;
        List <ViewPart> partList = new List <ViewPart>();
        List <ViewPart> list     = new List <ViewPart>();

        for (int i = 0; i < dtPart.Rows.Count; i++)
        {
            DataRow  row      = dtPart.Rows[i];
            bool     rowError = false;
            ViewPart part     = new ViewPart();
            if (!BatchUpdate)
            {
                Plant plant = this.Plants.SingleOrDefault(p => string.Equals(p.PlantCode, dtPart.Rows[i]["PlantCode"].ToString(), StringComparison.OrdinalIgnoreCase));

                CycleCountLevel cycleClevel = this.CycleCountLevels.SingleOrDefault(c => c.LevelName == dtPart.Rows[i]["LevelName"].ToString());
                PartStatus      partstatus  = this.PartStatus.SingleOrDefault(p => p.StatusName == dtPart.Rows[i]["StatusName"].ToString());
                Supplier        supplier    = this.Suppliers.SingleOrDefault(s => string.Equals(s.DUNS, dtPart.Rows[i]["DUNS"].ToString()));

                part.PartCode = dtPart.Rows[i]["PartCode"].ToString();
                if (supplier == null)
                {
                    string msg = string.Format("零件【{0}】的供应商DUNS【{1}】不存在", part.PartCode, dtPart.Rows[i]["DUNS"] + "");
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                    rowError = true;
                }
                else
                {
                    part.SupplierID = supplier.SupplierID;
                }

                if (plant == null)
                {
                    string msg = string.Format("零件【{0}】的工厂【{1}】不存在", part.PartCode, dtPart.Rows[i]["PlantCode"] + "");
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                    rowError = true;
                }
                else
                {
                    part.PlantID = plant.PlantID;
                }
                if (cycleClevel == null)
                {
                    string msg = string.Format("零件【{0}】的循环盘点级别【{1}】不存在", part.PartCode, dtPart.Rows[i]["LevelName"] + "");
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                    rowError = true;
                }
                else
                {
                    part.CycleCountLevel = cycleClevel.LevelID;
                }

                if (dtPart.Rows[i]["CategoryName"] != DBNull.Value && !string.IsNullOrEmpty(dtPart.Rows[i]["CategoryName"].ToString().Trim()))
                {
                    PartCategory partcategory = this.PartCategorys.SingleOrDefault(p => string.Equals(p.CategoryName, dtPart.Rows[i]["CategoryName"].ToString(), StringComparison.OrdinalIgnoreCase));
                    if (partcategory == null)
                    {
                        string msg = string.Format("零件【{0}】的物料类别【{1}】不存在", part.PartCode, dtPart.Rows[i]["CategoryName"] + "");
                        UCFileUpload1.AddErrorInfo(msg);
                        hasError = true;
                        rowError = true;
                    }
                    else
                    {
                        part.CategoryID = partcategory.CategoryID;
                    }
                }
                if (partstatus == null)
                {
                    string msg = string.Format("零件【{0}】的物料状态【{1}】不存在", part.PartCode, dtPart.Rows[i]["StatusName"] + "");
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                    rowError = true;
                }
                else
                {
                    part.PartStatus = partstatus.StatusID;
                }

                part.PartChineseName = dtPart.Rows[i]["PartChineseName"].ToString();
                part.WorkLocation    = dtPart.Rows[i]["WorkLocation"].ToString();
                part.Dloc            = dtPart.Rows[i]["Dloc"].ToString();
                part.Specs           = dtPart.Rows[i]["Specs"].ToString();
                part.FollowUp        = dtPart.Rows[i]["Followup"].ToString();
                part.Workshops       = dtPart.Rows[i]["Workshops"].ToString();
                part.Segments        = dtPart.Rows[i]["Segments"].ToString();
                if (!string.IsNullOrEmpty(dtPart.Rows[i]["CycleCountTimes"].ToString()))
                {
                    part.CycleCountTimes = short.Parse(dtPart.Rows[i]["CycleCountTimes"].ToString());
                }

                part.UpdateBy = CurrentUser.UserInfo.UserID;
                dtPart.Rows[i]["UserName"] = CurrentUser.UserInfo.UserName;
            }
            else
            {
                string plantCode = row["PlantCode"] + "";
                string partCode  = row["PartCode"] + "";
                string duns      = row["DUNS"] + "";
                //ViewPart tmpPart = new ViewPart { PlantCode = plantCode, PartCode = partCode, DUNS = duns };

                if (i % 1000 == 0)
                {
                    string startCode = partCode;
                    int    end       = i + 999;
                    if (end >= dtPart.Rows.Count)
                    {
                        end = dtPart.Rows.Count - 1;
                    }
                    string endCode = dtPart.Rows[end]["PartCode"].ToString();
                    list = Service.QueryPartsOfScope(startCode, endCode);
                }


                //List<ViewPart> list = new List<ViewPart> { tmpPart };
                //list = Service.QueryPartsByKey(list);
                part = list.Find(p => p.PartCode == partCode && p.PlantCode == plantCode && p.DUNS == duns);
                if (part == null)//(list == null || list.Count == 0)
                {
                    string msg = string.Format("工厂为【{0}】,供应商为【{1}】的零件【{2}】不存在", plantCode, duns, partCode);
                    UCFileUpload1.AddErrorInfo(msg);
                    hasError = true;
                    rowError = true;
                }
                else
                {
                    //part = list[0];
                    part.UpdateBy = CurrentUser.UserInfo.UserID;
                    switch (rblFields.SelectedIndex)
                    {
                    case 0:
                        part.FollowUp = row["Followup"].ToString();
                        break;

                    case 1:
                        part.Specs = row["Specs"].ToString();
                        break;

                    case 2:
                        part.Segments     = row["Segments"].ToString();
                        part.WorkLocation = row["WorkLocation"].ToString();
                        if (row["CategoryName"] != DBNull.Value && !string.IsNullOrEmpty(row["CategoryName"].ToString().Trim()))
                        {
                            PartCategory partcategory = this.PartCategorys.SingleOrDefault(p => string.Equals(p.CategoryName, row["CategoryName"].ToString(), StringComparison.OrdinalIgnoreCase));
                            if (partcategory == null)
                            {
                                string msg = string.Format("零件【{0}】的物料类别【{1}】不存在", part.PartCode, row["CategoryName"] + "");
                                UCFileUpload1.AddErrorInfo(msg);
                                hasError = true;
                                rowError = true;
                            }
                            else
                            {
                                part.CategoryID = partcategory.CategoryID;
                            }
                        }
                        else
                        {
                            part.CategoryID = null;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            if (!rowError)
            {
                partList.Add(part);
            }
        }

        if (!hasError)
        {
            Service.ImportPart(partList);

            BindDataControl(gvParts, dtPart);
            this.UCFileUpload1.AddSuccessInfo("上传文件成功", string.Empty, string.Empty);
        }
    }