Ejemplo n.º 1
0
        public static int InsertUnitConstraintFromExcel(DataTable dataTable)
        {
            using (var context = new AnnonContext())
            {
                try
                {
                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        var accessory = new Accessory
                        {
                            Unit = dataRow["Unit"].ToString(),
                            PartNo = dataRow["PartNo"].ToString(),
                            PartDescription = dataRow["PartDescription"].ToString(),
                            Model = dataRow["Model"].ToString(),
                            Heat = dataRow["Heat"].ToString(),
                            Cool = dataRow["Cool"].ToString(),
                            SystemSwitching = dataRow["SystemSwitching"].ToString(),
                            FanSwitching = dataRow["FanSwitching"].ToString(),
                            Application = dataRow["Application"].ToString(),
                            ChangeOver = dataRow["ChangeOver"].ToString(),
                            Use = dataRow["Use"].ToString(),
                            ListPrice = Convert.ToDecimal(dataRow["ListPrice"].ToString()),
                            Type = dataRow["Type"].ToString()

                        };
                        context.Accessories.Add(accessory);
                    }
                    return context.SaveChanges();
                }
                catch (Exception e)
                {
                    return -1;
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 插入一条附件记录
 /// </summary>
 /// <param name="accessory"></param>
 /// <param name="quantity"></param>
 /// <returns></returns>
 public static int insertIntoAccessoryOrder(Accessory accessory,int quantity)
 {
     using (var context = new AnnonContext())
     {
         try
         {
             var accessoryOrder = new AccessoryOrder
             {
                 Quantity = quantity,
                 PartNo = accessory.PartNo,
                 PartDescription = accessory.PartDescription,
                 ListPrice=accessory.ListPrice,
                 Price = accessory.ListPrice * quantity
             };
             context.AccessoryOrders.Add(accessoryOrder);
             return context.SaveChanges();
         }
         catch (Exception e)
         {
             return -1;
         }
     }
 }