using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Telerik.Web.UI; namespace VRS.Management.VSAT { public partial class FlowManage : BasePage { DataService.BLL.pro_flow bll = new DataService.BLL.pro_flow(); DataService.BLL.admin_log log = new DataService.BLL.admin_log(); DataService.BLL.pro_scene bll_pro_scene = new DataService.BLL.pro_scene(); DataService.BLL.pro_subject bll_pro_subject = new DataService.BLL.pro_subject(); DataService.BLL.pro_subject_proc bll_pro_subject_proc = new DataService.BLL.pro_subject_proc(); protected override void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataLoad(); } } protected void DataLoad() { //科目id //RadListBoxSource.Items[0].Index string Id = Request.Params["Id"]; var query = new StringBuilder(" 1 = 1 "); if (!string.IsNullOrWhiteSpace(Id.Trim())) { var pro_scene = bll_pro_scene.GetModelBySubject(Id); if (null == pro_scene) { RadAjaxManager1.ResponseScripts.Add("alert('场景为空,不能操作!');CloseAndRebind();"); return; } query.AppendFormat(" and subject_id = '{0}' ", Id.Trim()); var list_dest = bll.GetModelListByStep(query.ToString()); var list_source = bll_pro_subject_proc.GetModelList(" subject_id='" + Id.Trim() + "' "); var flow_tips = list_dest.Select(s => s.tip).ToArray(); var flow_score = list_source.Where(s => flow_tips.Contains(s.tip)).Select(s => s.score).DefaultIfEmpty().Sum(); System.Web.UI.HtmlControls.HtmlGenericControl span_name = RadListBoxDestination.Header.FindControl("span_name") as System.Web.UI.HtmlControls.HtmlGenericControl; if (null != span_name) { span_name.InnerHtml = " 总分-" + flow_score + "分"; } /* * var json = pro_scene.json_name; var json_file = Server.MapPath("~/Upload/Scenes/" + json); var list_source = get_json_flow(json_file, "Procedure"); if (!string.IsNullOrWhiteSpace(Id.Trim())) { var list = bll_pro_subject_proc.GetModelList(" subject_id='" + Id.Trim() + "' "); if (list.Count <= 0) { for (var i = 0; i < list_source.Count; i++) { var item = list_source[i]; var proc = new DataService.Model.pro_subject_proc(); proc.proc_id = bll_pro_subject_proc.GetNewId(); proc.subject_id = Id.Trim(); proc.name = item.desc; proc.step = item.step.ToString(); proc.tip = item.tip; bll_pro_subject_proc.Add(proc); } } }*/ for (var i = list_source.Count - 1; i >= 0; i--) { var item = list_source[i]; var exists = list_dest.FirstOrDefault(s => s.tip == item.tip); if (null != exists) { list_source.RemoveAt(i); } } RadListBoxSource.DataSource = list_source; //RadListBoxSource.DataValueField = "desc"; RadListBoxSource.DataValueField = "name"; RadListBoxSource.DataTextField = "tip"; RadListBoxSource.DataSortField = "step"; RadListBoxSource.DataBind(); RadListBoxDestination.DataSource = list_dest; RadListBoxDestination.DataValueField = "desc"; RadListBoxDestination.DataTextField = "tip"; RadListBoxDestination.DataSortField = "step"; RadListBoxDestination.DataBind(); } else { OnError(null); } } protected void btnSure_Click(object sender, EventArgs e) { string Id = Request.Params["Id"]; var items = RadListBoxDestination.Items; /* if (items.Count <= 0) { RadAjaxManager1.ResponseScripts.Add("alert('流程不能为空!');"); return; } */ var array = new List(); var name_array = new List(); foreach (var item in items) { var obj = item as Telerik.Web.UI.ControlItem; array.Add(obj.Text); name_array.Add(obj.Value); } var tips = string.Join(",", array); var names = string.Join(",", name_array); var model = bll_pro_subject.GetModel(Id); var flag = bll.DeleteAndBatchAdd(tips, names, Id, model.r1); if (flag) { log.write_log("保存流程成功。" + "科目名称:" + model.subject_name + ",科目ID:" + Id); RadAjaxManager1.ResponseScripts.Add("alert('保存成功!');CloseAndRebind();"); } else { RadAjaxManager1.ResponseScripts.Add("alert('保存失败!');"); } } public string read_json(string json_file, string key) { using (System.IO.StreamReader file = System.IO.File.OpenText(json_file)) { using (JsonTextReader reader = new JsonTextReader(file)) { JObject o = (JObject)JToken.ReadFrom(reader); var value = o[key].ToString(); return value; } } } public List get_json_flow(string json_file, string key) { List list = new List(); using (System.IO.StreamReader file = System.IO.File.OpenText(json_file)) { using (JsonTextReader reader = new JsonTextReader(file)) { JObject o = (JObject)JToken.ReadFrom(reader); var value = o[key].ToString(); JArray array = JArray.Parse(value); for (int i = 0; i < array.Count; i++) { var item = new DataService.Model.pro_flow(); JObject jb = JObject.Parse(array[i].ToString()); item.tip = jb["tip"].ToString(); item.step = int.Parse(jb["step"].ToString()); item.desc = jb["name"].ToString(); list.Add(item); } return list; } } } protected void RadListBoxSource_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e) { RadListBoxSource.DataBind(); RadListBoxDestination.DataBind(); } protected void RadListBoxDestination_Reordered(object sender, RadListBoxEventArgs e) { RadListBoxDestination.DataBind(); } } }