public EmsModel.JsonModel CreateOrder(Hashtable ht) { try { //string[] Str = ht["YSelectStr"].ToString().Split(',');// //订单编号前缀 string prefix = ""; if (ht["Type"].ToString() == "0") { prefix = "SY"; } else if (ht["Type"].ToString() == "1") { prefix = "YJ"; } EmsDAL.OrderEquipDetail ModelOrderEquipDetail = new EmsDAL.OrderEquipDetail(); //订单赋值 EmsModel.OrderInfo ModelOrderInfo = new EmsModel.OrderInfo(); ModelOrderInfo.OrderNo = prefix; ModelOrderInfo.LoanName = ht["LoanName"].ToString(); ModelOrderInfo.ExperimentId = Convert.ToInt32(ht["ExperimentId"]); ModelOrderInfo.Type = Convert.ToByte(ht["Type"]); ModelOrderInfo.Status = 0; ModelOrderInfo.Creator = ht["Creator"].ToString(); ModelOrderInfo.CreateTime = DateTime.Now; ModelOrderInfo.IsDelete = 0; //修改实验“是否生成订单”状态 EmsDAL.PlanExperiment DALPE = new EmsDAL.PlanExperiment(); EmsModel.PlanExperiment ModelPE = DALPE.GetData(ht["ExperimentId"].ToString())[0]; ModelPE.Status = 1;//将实验状态赋值为“已生成订单” //事务 using (SqlTransaction trans = dal.GetTran()) { try { //添加订单 int orderId = dal.Add(trans, ModelOrderInfo); if (orderId <= 0) { //回滚 trans.Rollback(); //定义JSON标准格式实体中 JsonModel jsonModel1 = new JsonModel(); jsonModel1.Status = "no"; jsonModel1.Msg = "订单生成失败"; return(jsonModel1); } //修改订单编号 ModelOrderInfo.Id = orderId; ModelOrderInfo.OrderNo = prefix + DateTime.Now.ToString("yyMMddHHmmss") + orderId; int UpdateReturn = dal.Update(trans, ModelOrderInfo); if (UpdateReturn != 1) { //回滚 trans.Rollback(); //定义JSON标准格式实体中 JsonModel jsonModel1 = new JsonModel(); jsonModel1.Status = "no"; jsonModel1.Msg = "订单生成失败"; return(jsonModel1); } //修改实验状态 int UpdatePEReturn = DALPE.Update(trans, ModelPE); if (UpdatePEReturn != 1) { //回滚 trans.Rollback(); //定义JSON标准格式实体中 JsonModel jsonModel1 = new JsonModel(); jsonModel1.Status = "no"; jsonModel1.Msg = "订单生成失败"; return(jsonModel1); } #region 添加订单设备详情 ////生成订单 //int AddCount = 0; //int SuccessCount = 0; ////循环添加设备 //foreach (string item in Str) //{ // int EquipKindId = Convert.ToInt32(item.Substring(0, item.IndexOf("-"))); // int Count = Convert.ToInt32(item.Substring(item.IndexOf("-") + 1, item.IndexOf(":") - item.IndexOf("-") - 1)); // string InstrumentEquip = item.Substring(item.IndexOf(":") + 1); // //更新需要添加的设备数量 // AddCount += Count; // //每个设备添加一条数据 // for (int i = 0; i < Count; i++) // { // //model赋值 // EmsModel.OrderEquipDetail model = new EmsModel.OrderEquipDetail(); // model.OrderId = orderId; // model.InventoryKindId = EquipKindId; // model.EquipId = ""; // model.InstrumentEquip = InstrumentEquip; // model.EquipDetailName = ""; // model.Type = 0; // int ret = ModelOrderEquipDetail.Add(trans, model); // if (ret > 0) // { // SuccessCount++; // } // } //} //if (AddCount != SuccessCount) //{ // //回滚 // trans.Rollback(); // //定义JSON标准格式实体中 // JsonModel jsonModel1 = new JsonModel(); // jsonModel1.Status = "no"; // jsonModel1.Msg = "订单生成失败"; // return jsonModel1; //} //else //{ // //提交 // trans.Commit(); //} #endregion //提交 trans.Commit(); } catch (Exception) { //回滚 trans.Rollback(); throw; } } //定义JSON标准格式实体中 JsonModel jsonModel = new JsonModel(); jsonModel.Status = "ok"; jsonModel.Msg = "订单生成成功"; return(jsonModel); } catch (Exception ex) { JsonModel jsonModel = new JsonModel(); jsonModel.Status = "error"; jsonModel.Msg = ex.ToString(); return(jsonModel); } }
/// <summary> /// 修改实验 /// </summary> /// <param name="ht">参数Key:Id</param> /// <returns></returns> public JsonModel UpdateExperiment(Hashtable ht) { try { int Id = Convert.ToInt32(ht["Id"].ToString()); EmsModel.PlanExperiment Model = dal.GetData(ht["Id"].ToString())[0]; Model.Name = ht["Name"].ToString();//实验名称 Model.Type = Convert.ToByte(ht["Type"].ToString()); Model.IsOpen = Convert.ToByte(ht["IsOpen"].ToString()); Model.StartDate = Convert.ToDateTime(ht["StartDate"].ToString()); Model.Week = Convert.ToInt32(ht["Week"].ToString()); Model.Weekday = Convert.ToInt32(ht["Weekday"].ToString()); Model.ClassHour = Convert.ToInt32(ht["ClassHour"].ToString()); Model.Part = ht["Part"].ToString(); Model.ComputerRoom = Convert.ToInt32(ht["ComputerRoom"].ToString()); Model.Place = Convert.ToInt32(ht["Place"].ToString()); Model.GroupMemberNumber = Convert.ToInt32(ht["GroupMemberNumber"].ToString()); Model.GroupNumber = Convert.ToInt32(ht["GroupNumber"].ToString()); Model.NeedEquip = ht["NeedEquip"].ToString(); Model.Contents = ht["Contents"].ToString();//实验内容 //Model.Creator = Creator;//创建人登录名 //Model.CreateTime = DateTime.Now;//创建时间 Model.Editor = ht["Editor"].ToString(); //修改人登录名 Model.UpdateTime = DateTime.Now; //修改时间 Model.ClassName = ht["Class"].ToString(); //上课班级 Model.Category = Convert.ToByte(ht["Category"].ToString()); //实验类别 0室内上课;1室外上课 //定义JSON标准格式实体中 JsonModel jsonModel = new JsonModel(); int obj = new EmsDAL.PlanExperiment().getPlanExperiment(Model.Name.ToString(), Model.PlanId.ToString()); if (obj > 0) { jsonModel.Status = "cf"; jsonModel.Msg = "当前课程下已经有此实验!"; } else { int result = dal.Update(Model); if (result == 0) { jsonModel.Status = "no"; jsonModel.Msg = "添加失败"; } else { jsonModel.Status = "ok"; jsonModel.Msg = "添加成功"; } } return(jsonModel); #region MyRegion //string[] ClassId = ht["Class"].ToString().Split(','); //if (string.IsNullOrWhiteSpace(ht["Class"].ToString())) //{ // ClassId = new string[0]; //} ////定义JSON标准格式实体中 //JsonModel jsonModel = new JsonModel(); ////事务 //using (SqlTransaction trans = dal.GetTran()) //{ // try // { // int result = dal.Update(trans, Model); // if (result == 0) // { // //回滚 // trans.Rollback(); // jsonModel.Status = "no"; // jsonModel.Msg = "修改失败"; // return jsonModel; // } // EmsDAL.ExperimentClassInfo DALEC = new EmsDAL.ExperimentClassInfo(); // //清除实验班级 // DALEC.DeleteEC(trans, Id); // int AddCount = 0; // foreach (string id in ClassId) // { // EmsModel.ExperimentClassInfo ModelEC = new EmsModel.ExperimentClassInfo(); // ModelEC.ExperimentId = Id; // ModelEC.ClassId = Convert.ToInt32(id); // int resultEC = DALEC.Add(trans, ModelEC); // if (resultEC > 0) // { // AddCount++; // } // } // if (ClassId.Length != AddCount) // { // //回滚 // trans.Rollback(); // jsonModel.Status = "no"; // jsonModel.Msg = "班级保存失败"; // } // else // { // //提交 // trans.Commit(); // jsonModel.Status = "ok"; // jsonModel.Msg = "修改成功"; // } // return jsonModel; // } // catch (Exception) // { // //回滚 // trans.Rollback(); // throw; // } //} #endregion } catch (Exception ex) { JsonModel jsonModel = new JsonModel(); jsonModel.Status = "error"; jsonModel.Msg = ex.ToString(); return(jsonModel); } }