Example #1
0
        private string AddGiveBill(DataTable dt)
        {
            GiveBill bill = DataTableToEntites.GetEntity <GiveBill>(dt.Rows[0]);

            bill.Record = HandleRecords(dt);
            GiveBillService Service = new GiveBillService();

            Service.SaveData(bill);
            return(bill.BillCode);
        }
Example #2
0
        /// <summary>
        /// 批量导入交货单
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private string AddManyGiveBills(DataTable dt)
        {
            string          res     = "";
            GiveBillService Service = new GiveBillService();
            //转成集合
            List <ManyGiveBillsModel> list = new List <ManyGiveBillsModel>();

            foreach (DataRow row in dt.Rows)
            {
                ManyGiveBillsModel model = new ManyGiveBillsModel()
                {
                    LBBillCode     = row[0].ToString(),
                    LBCustomerCode = row[1].ToString(),
                    LBCustomerName = row[2].ToString(),
                    ItemCode       = row[4].ToString(),
                    ItemName       = row[5].ToString(),
                    ItemBatch      = row[7].ToString(),
                    Count          = Convert.ToDouble(row[8]),
                    Weight         = Convert.ToDouble(row[9]),
                    ItemLocationId = row[10].ToString(),
                    ItemLocation   = row[11].ToString(),
                    LBContacts     = row[12].ToString(),
                    LBPhone        = row[13].ToString(),
                    LBSendAddress  = row[14].ToString(),
                    LBMailCode     = row[15].ToString(),
                    LBBillDate     = Convert.ToDateTime(row[16]),
                    WarehouseId    = Convert.ToInt32(row[17]),
                    Warehouse      = row[18].ToString(),
                    ChargePerson   = row[19].ToString()
                };
                list.Add(model);
            }
            //按立邦单号排序
            list.Sort((x, y) =>
            {
                int value = x.LBBillCode.CompareTo(y.LBBillCode);
                if (value == 0)
                {
                    value = x.ItemCode.CompareTo(y.ItemCode);
                }
                return(value);
            });
            string   CurrentLBBillCode = ""; //当前立邦单号
            GiveBill bill = null;            //当前交货单

            foreach (var item in list)
            {
                //新的一条单据
                if (item.LBBillCode != CurrentLBBillCode)
                {
                    //保存上一张单据
                    if (CurrentLBBillCode != "")
                    {
                        res += Service.SaveImport(bill);
                    }
                    //新建下一张单据
                    bill = new GiveBill()
                    {
                        LBBillCode     = item.LBBillCode,
                        LBCustomerCode = item.LBCustomerCode,
                        LBCustomerName = item.LBCustomerName,
                        LBContacts     = item.LBContacts,
                        LBPhone        = item.LBPhone,
                        LBSendAddress  = item.LBSendAddress,
                        LBMailCode     = item.LBMailCode,
                        LBBillDate     = item.LBBillDate,
                        WarehouseId    = item.WarehouseId,
                        Warehouse      = item.Warehouse,
                        ChargePerson   = item.ChargePerson
                    };
                }
                Record record = new Record()
                {
                    ItemCode = item.ItemCode, ItemName = item.ItemName, ItemBatch = item.ItemBatch, Count = item.Count, Weight = item.Weight, ItemLocation = item.ItemLocation, ItemLocationId = item.ItemLocationId
                };
                bill.Record.Add(record);
                CurrentLBBillCode = item.LBBillCode;
            }
            //循环结束 保存最后一条
            if (bill != null)
            {
                res += Service.SaveImport(bill);
            }
            return(res);
        }