public ActionResult AjaxUploadExcel()
        {
            HttpPostedFileBase upload = Request.Files["upLoadFile"];
            try
            {
                if (Request.Cookies["User"] != null)
                {
                    HttpCookie aCookie = Request.Cookies["User"];
                    string realname = Server.UrlDecode(aCookie["RealName"]);
                    int colnum = 0, totalnum = 0;
                    if (upload != null && upload.ContentLength > 0)
                    {
                        string filePath = @"D:\temp\InfoManage.xlsx";
                        upload.SaveAs(filePath);

                        using (InfoManageDataContext context = new InfoManageDataContext())
                        {
                            #region EquipmentsStorage
                            string InfoManageConnectionStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=YES\"";
                            DataSet EquipmentsStorageDS = new DataSet();
                            using (OleDbConnection EquipmentsStorageConn = new OleDbConnection(InfoManageConnectionStr))
                            {
                                string strCom = "SELECT * FROM [Sheet1$]";
                                EquipmentsStorageConn.Open();
                                OleDbDataAdapter WeatherPhenomenonCommand = new OleDbDataAdapter(strCom, EquipmentsStorageConn);
                                WeatherPhenomenonCommand.Fill(EquipmentsStorageDS, "[Sheet1]");
                                EquipmentsStorageConn.Close();
                            }
                            DataTable StationsDSDataTable = EquipmentsStorageDS.Tables[0];
                            foreach (DataRow row in StationsDSDataTable.Rows)
                            {
                                string storname = row.ItemArray[6].ToString().Trim();
                                StoragesInfo stor = context.StoragesInfos.Where(c => c.StoragesInfoName.Equals(storname)).FirstOrDefault();
                                if (stor != null)
                                {
                                    EquipmentsStorage station = new EquipmentsStorage();
                                    station.SparePartsCode = row.ItemArray[0].ToString().Trim();
                                    station.SparePartsType = row.ItemArray[2].ToString().Trim();
                                    station.ApplicableModels = row.ItemArray[3].ToString().Trim();
                                    station.SparePartsManufacturer = row.ItemArray[4].ToString().Trim();
                                    station.Operator = row.ItemArray[5].ToString().Trim();
                                    station.SparePartsBelongingStatus = stor.StoragesInfoID;
                                    station.TurnInDate = DateTime.ParseExact(row.ItemArray[7].ToString().Trim() + " 10:30", AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                    station.CheckDate = DateTime.ParseExact(row.ItemArray[8].ToString().Trim() + " 10:30", AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);

                                    station.SparePartsPic = "   ";
                                    station.SparePartsCertificatePic = "   ";
                                    station.SparePartsStatus = 1;
                                    station.MaxError = "   ";

                                    station.LastModifier = AllConsts.adminName;
                                    station.LastModifyDate = DateTime.Now;

                                    string tmp123 = row.ItemArray[1].ToString().Trim();
                                    Element ele = context.Elements.Where(c => c.SparePartsName.Equals(tmp123)).FirstOrDefault();
                                    if (ele != null)
                                    {
                                        station.ElementID = ele.ElementID;
                                        if (ele.ElementID.Equals(12) && ele.isHelper.Equals(false))
                                        {
                                            station.VaildDate = station.CheckDate.AddYears(1);
                                        }
                                        if ((!ele.ElementID.Equals(12)) && ele.isHelper.Equals(false))
                                        {
                                            station.VaildDate = station.CheckDate.AddYears(2);
                                        }
                                        if (ele.isHelper.Equals(true))
                                        {
                                            station.VaildDate = DateTime.ParseExact(AllConsts.MAX_DATE_HOUR_MINUTE, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                        }
                                        EquipmentsStorage newequip = context.EquipmentsStorages.Where(c => c.SparePartsCode.Equals(station.SparePartsCode)).FirstOrDefault();
                                        if (newequip == null)
                                        {
                                            context.EquipmentsStorages.Add(station);
                                            colnum++;
                                        }
                                        //else
                                        //{
                                        //    newequip.SparePartsCode = row.ItemArray[0].ToString().Trim();
                                        //    newequip.SparePartsType = row.ItemArray[2].ToString().Trim();
                                        //    newequip.ApplicableModels = row.ItemArray[3].ToString().Trim();
                                        //    newequip.SparePartsManufacturer = row.ItemArray[4].ToString().Trim();
                                        //    newequip.Operator = row.ItemArray[5].ToString().Trim();
                                        //    //newequip.SparePartsBelongingStatus = stor.StoragesInfoID;
                                        //    newequip.TurnInDate = DateTime.ParseExact(row.ItemArray[7].ToString().Trim() + " 10:30", AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                        //    newequip.CheckDate = DateTime.ParseExact(row.ItemArray[8].ToString().Trim() + " 10:30", AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                        //    newequip.ElementID = ele.ElementID;
                                        //    if (ele.ElementID.Equals(12) && ele.isHelper.Equals(false))
                                        //    {
                                        //        newequip.VaildDate = newequip.CheckDate.AddYears(1);
                                        //    }
                                        //    if ((!ele.ElementID.Equals(12)) && ele.isHelper.Equals(false))
                                        //    {
                                        //        newequip.VaildDate = newequip.CheckDate.AddYears(2);
                                        //    }
                                        //    if (ele.isHelper.Equals(true))
                                        //    {
                                        //        newequip.VaildDate = DateTime.ParseExact(AllConsts.MAX_DATE_HOUR_MINUTE, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                        //    }
                                        //    newequip.LastModifier = AllConsts.adminName;
                                        //    newequip.LastModifyDate = DateTime.Now;
                                        //}
                                        context.SaveChanges();
                                        totalnum++;
                                    }
                                    //else
                                    //{
                                    //    int elcount = context.Elements.Count();
                                    //    Element neweles = new Element();
                                    //    neweles.ElementID = elcount + 1;
                                    //    neweles.ElementName = row.ItemArray[1].ToString().Trim();
                                    //    neweles.ElementENName = row.ItemArray[1].ToString().Trim(); ;
                                    //    neweles.isHelper = false;
                                    //    neweles.SparePartsName = row.ItemArray[1].ToString().Trim(); ;
                                    //    context.Elements.Add(neweles);
                                    //    context.SaveChanges();

                                    //    string tmpname = row.ItemArray[1].ToString().Trim();
                                    //    Element eletmp = context.Elements.Where(c => c.SparePartsName.Equals(tmpname)).FirstOrDefault();
                                    //    if (eletmp != null)
                                    //    {
                                    //        station.ElementID = eletmp.ElementID;
                                    //        if (station.ElementID.Equals(12) && eletmp.isHelper.Equals(false))
                                    //        {
                                    //            station.VaildDate = station.CheckDate.AddYears(1);
                                    //        }
                                    //        if ((!station.ElementID.Equals(12)) && eletmp.isHelper.Equals(false))
                                    //        {
                                    //            station.VaildDate = station.CheckDate.AddYears(2);
                                    //        }
                                    //        EquipmentsStorage newequip = context.EquipmentsStorages.Where(c => c.SparePartsCode.Equals(station.SparePartsCode)).FirstOrDefault();
                                    //        if (newequip != null)
                                    //        {
                                    //            newequip.SparePartsCode = row.ItemArray[0].ToString().Trim();
                                    //            newequip.SparePartsType = row.ItemArray[2].ToString().Trim();
                                    //            newequip.ApplicableModels = row.ItemArray[3].ToString().Trim();
                                    //            newequip.SparePartsManufacturer = row.ItemArray[4].ToString().Trim();
                                    //            newequip.Operator = row.ItemArray[5].ToString().Trim();
                                    //            newequip.SparePartsBelongingStatus = stor.StoragesInfoID;
                                    //            newequip.TurnInDate = DateTime.ParseExact(row.ItemArray[7].ToString().Trim() + " 10:30", AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                    //            newequip.CheckDate = DateTime.ParseExact(row.ItemArray[8].ToString().Trim() + " 10:30", AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                    //            newequip.VaildDate = DateTime.ParseExact(AllConsts.MAX_DATE_HOUR_MINUTE, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                    //            newequip.LastModifier = AllConsts.adminName;
                                    //            newequip.LastModifyDate = DateTime.Now;
                                    //        }
                                    //        else
                                    //            context.EquipmentsStorages.Add(station);
                                    //        context.SaveChanges();
                                    //        colnum++;
                                    //    }
                                    //}
                                }
                            }
                            #endregion
                            if (System.IO.File.Exists(filePath))
                            {
                                System.IO.File.Delete(filePath);
                            }
                        }
                    }
                    return Json("总" + totalnum + "记录,导入成功" + colnum + "记录", JsonRequestBehavior.AllowGet);
                }
                return Json(-1, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(-2, JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult AjaxSetTurnInStorageList(
            int ElementID, string SparePartsType, string ApplicableModels,
            string SparePartsCode, string Operator, string TurnInDate, int SparePartsStatus,
            int SparePartsBelongingStatus, string SparePartsManufacturer, string CheckDate, string VaildDate)
        {
            try
            {
                if (Request.Cookies["User"] != null)
                {
                    HttpCookie aCookie = Request.Cookies["User"];
                    ViewBag.RealName = Server.UrlDecode(aCookie["RealName"]);
                    int id = Convert.ToInt32(Server.UrlDecode(aCookie["ID"]));

                    using (MemberShipDataContext context = new MemberShipDataContext())
                    {
                        UserProfile usr = context.UserProfiles.Find(id);
                        if (null != usr)
                        {
                            using (InfoManageDataContext InfoManageContext = new InfoManageDataContext())
                            {
                                EquipmentsStorage newTurnInStorage = new EquipmentsStorage();
                                newTurnInStorage.SparePartsType = SparePartsType;
                                newTurnInStorage.ApplicableModels = ApplicableModels;
                                newTurnInStorage.SparePartsCode = SparePartsCode.Trim();
                                newTurnInStorage.TurnInDate = DateTime.ParseExact(TurnInDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                newTurnInStorage.Operator = Operator;
                                newTurnInStorage.SparePartsStatus = SparePartsStatus;
                                newTurnInStorage.SparePartsBelongingStatus = SparePartsBelongingStatus;
                                newTurnInStorage.CheckDate = DateTime.ParseExact(CheckDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                newTurnInStorage.VaildDate = DateTime.ParseExact(VaildDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                newTurnInStorage.SparePartsManufacturer = SparePartsManufacturer;
                                newTurnInStorage.ElementID = ElementID;
                                newTurnInStorage.LastModifyDate = DateTime.Now;
                                newTurnInStorage.LastModifier = Operator;
                                EquipmentsStorage result = InfoManageContext.EquipmentsStorages.Where(c => c.SparePartsCode.Equals(SparePartsCode)).FirstOrDefault();
                                if (null == result)
                                {
                                    InfoManageContext.EquipmentsStorages.Add(newTurnInStorage);
                                }
                                else
                                {
                                    result.SparePartsType = newTurnInStorage.SparePartsType;
                                    result.ApplicableModels = newTurnInStorage.ApplicableModels;
                                    result.TurnInDate = newTurnInStorage.TurnInDate;
                                    result.Operator = newTurnInStorage.Operator;
                                    result.CheckDate = newTurnInStorage.CheckDate;
                                    result.VaildDate = newTurnInStorage.VaildDate;
                                    result.SparePartsManufacturer = newTurnInStorage.SparePartsManufacturer;
                                    result.ElementID = newTurnInStorage.ElementID;
                                    result.SparePartsBelongingStatus = SparePartsBelongingStatus;
                                    result.LastModifyDate = DateTime.Now;
                                    result.LastModifier = Operator;
                                }

                                UserAction newaction = new UserAction();
                                newaction.ID = usr.ID;
                                newaction.RealName = usr.RealName;
                                newaction.ActionName = "AjaxSetTurnInStorageList";
                                newaction.CreateTime = DateTime.Now;
                                newaction.LastModifyTime = newaction.CreateTime;
                                InfoManageContext.UserActions.Add(newaction);

                                InfoManageContext.SaveChanges();
                                return Json("OK", JsonRequestBehavior.AllowGet);
                            }
                        }
                    }
                }
                return Json("NO", JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json("NO", JsonRequestBehavior.AllowGet);
            }
        }