private void AddDevicePlan(wy_device_planEntity entity) { wy_device_planEntity nentity = null; try { if (!string.IsNullOrEmpty(entity.classid)) { string[] classids = entity.classid.Split(','); for (int i = 0; i < classids.Length; i++) { var sql = @"select * from wy_device_plan where p_number='" + entity.p_number + "' and fyear=" + entity.fyear + " and fmonth=" + (i + 1); var model = this.BaseRepository().FindList(sql).FirstOrDefault(); if (model == null) { if (!string.IsNullOrEmpty(classids[i])) { nentity = new wy_device_planEntity(); nentity.fyear = entity.fyear; nentity.fmonth = (i + 1); nentity.p_number = entity.p_number; nentity.classid = classids[i]; nentity.fyear = entity.fyear; nentity.fgroupid = entity.fgroupid; nentity.fstatusid = 0; nentity.planid = DeviceService.GetMaxID_String("right(planid,8)", "wy_device_plan", 8); this.BaseRepository().Insert(nentity); } } else { if (string.IsNullOrEmpty(classids[i])) { var sqldele = @"delete from wy_device_plan where p_number='" + entity.p_number + "' and fyear=" + entity.fyear + " and fmonth=" + (i + 1); this.BaseRepository().ExecuteBySql(sqldele); } else { StringBuilder builder = new StringBuilder(); builder.Append("update wy_device_plan set "); builder.Append("classid=@classid,"); builder.Append("finfo='',"); builder.Append("fstatusid=@fstatusid,"); builder.Append("fgroupid=@fgroupid"); builder.Append(" where p_number=@p_number and fyear=@fyear and fmonth=@fmonth"); DbParameter[] parameter = { DbParameters.CreateDbParameter("@classid", classids[i]), DbParameters.CreateDbParameter("@fstatusid", 0), DbParameters.CreateDbParameter("@fgroupid", entity.fgroupid), DbParameters.CreateDbParameter("@p_number", entity.p_number), DbParameters.CreateDbParameter("@fyear", entity.fyear), DbParameters.CreateDbParameter("@fmonth", (i + 1)) }; this.BaseRepository().ExecuteBySql(builder.ToString(), parameter); } } } } } catch (System.Exception ex) { throw; } }