public static void CreateTemp() { if (_temp == null) { _temp = new TempViewModel(); } }
public frmSNO(UserInformation userInformation) { InitializeComponent(); // RawMaterialCode = string.Empty; // RawMaterialViewMode vm = new RawMaterialViewMode(userInformation, RawMaterialCode, OperationMode.AddNew); // this.DataContext = vm; // if (vm.CloseAction == null) // vm.CloseAction = new Action(() => mdiChild.Close()); TempViewModel vm = new TempViewModel(userInformation); this.DataContext = vm; // custComboBoxCol.ItemsSource = vm.DtData; }
/// <summary> /// 创建Controller文件 /// </summary> /// <param name="modelName"></param> public void GenerateController(string modelName) { TempViewModel viewModel = new TempViewModel() { ProjectName = "CareerCRM", ControllerName = modelName, ModelName = modelName, DataList = null }; string content = Render <TempViewModel>("~/Template/ControllerTemp.cshtml", viewModel); content = content.Replace("<p>", "").Replace("</p>", ""); if (!Directory.Exists(controllerPath)) { Directory.CreateDirectory(controllerPath); } System.IO.File.WriteAllText($"{controllerPath}{modelName}Controller.cs", content, Encoding.UTF8); }
/// <summary> /// 生成应用层文件 /// </summary> /// <param name="modelName"></param> public void GenerateApp(string modelName, List <string> fields) { List <string> formList = fields.Where(m => m.StartsWith("form_")).ToList(); //表单字段 List <string> listViewList = fields.Where(m => m.StartsWith("field_")).ToList(); //表单字段 List <string> searchList = fields.Where(m => m.StartsWith("search_")).ToList(); //表单字段 List <Type> list = GetAllTypes("*.Repository.dll"); Type modelType = list.Where(u => u.Name == modelName).FirstOrDefault(); List <PropertyInfo> pros = modelType.GetProperties().ToList(); List <string> searchDataList = new List <string>(); foreach (string f in searchList) { string fieldName = f.Replace("search_", "").Trim(); PropertyInfo pro = pros.Where(m => m.Name == fieldName).FirstOrDefault(); Type t = pro.PropertyType; string fieldType = "string"; string descriptionName = ""; DescriptionAttribute[] v = (DescriptionAttribute[])pro.GetCustomAttributes(typeof(DescriptionAttribute), false); if (v.Count() > 0) { string description = v[0].Description; descriptionName = description.Length > 0 ? description : fieldName; } if (CTS_Dict.ContainsKey(t.Name)) { fieldType = CTS_Dict[t.Name]; } searchDataList.Add(fieldName + "," + descriptionName + "," + fieldType); } TempViewModel viewModel = new TempViewModel() { ProjectName = "CareerCRM", ControllerName = modelName, ModelName = modelName, DataList = formList, ListViewDataList = listViewList, SearchDataList = searchDataList }; string content = Render <TempViewModel>("~/Template/AppLicationTemp.cshtml", viewModel); content = content.Replace("<p>", "").Replace("</p>", ""); System.IO.File.WriteAllText($"{applacationPath}{modelName}App.cs", content, Encoding.UTF8); }
/// <summary> /// 创建View文件 /// </summary> /// <param name="modelName"></param> /// <param name="fields"></param> public void GenerateView(string modelName, List <string> fields) { List <string> searchList = fields.Where(m => m.StartsWith("search_")).ToList(); //搜索字段 List <string> fieldList = fields.Where(m => m.StartsWith("field_")).ToList(); //列表字段 List <string> formList = fields.Where(m => m.StartsWith("form_")).ToList(); //表单字段 List <string> contentList = fields.Where(m => m.StartsWith("content_")).ToList(); //需要设置的富文本字段 List <Type> list = GetAllTypes("*.Repository.dll"); Type modelType = list.Where(u => u.Name == modelName).FirstOrDefault(); List <PropertyInfo> pros = modelType.GetProperties().ToList(); Dictionary <string, List <string> > dict = new Dictionary <string, List <string> > { { "searchList", searchList }, { "fieldList", fieldList }, { "formList", formList }, { "contentList", contentList } }; List <string> searchDataList = new List <string>(); List <string> formDataList = new List <string>(); List <string> tableDataList = new List <string>(); List <string> contentDataList = new List <string>(); foreach (KeyValuePair <string, List <string> > item in dict) { foreach (string f in item.Value) { string fieldName = ""; if (item.Key == "searchList") { fieldName = f.Replace("search_", "").Trim(); } else if (item.Key == "fieldList") { fieldName = f.Replace("field_", "").Trim(); } else if (item.Key == "formList") { fieldName = f.Replace("form_", "").Trim(); } else if (item.Key == "contentList") { fieldName = f.Replace("content_", "").Trim(); } PropertyInfo pro = pros.Where(m => m.Name == fieldName).FirstOrDefault(); Type t = pro.PropertyType; string fieldType = "string"; string descriptionName = ""; DescriptionAttribute[] v = (DescriptionAttribute[])pro.GetCustomAttributes(typeof(DescriptionAttribute), false); if (v.Count() > 0) { string description = v[0].Description; descriptionName = description.Length > 0 ? description : fieldName; } if (CTS_Dict.ContainsKey(t.Name)) { fieldType = CTS_Dict[t.Name]; } if (item.Key == "searchList") { searchDataList.Add(fieldName + "," + descriptionName + "," + fieldType); } else if (item.Key == "fieldList") { tableDataList.Add(fieldName + "," + descriptionName + "," + fieldType); } else if (item.Key == "formList") { formDataList.Add(fieldName + "," + descriptionName + "," + fieldType); } else if (item.Key == "contentList") { contentDataList.Add(fieldName); } } } string content = ""; if (!Directory.Exists(viewPath)) { Directory.CreateDirectory(viewPath); } TempViewModel viewModel = new TempViewModel() { ProjectName = "CareerCRM", ControllerName = modelName, ModelName = modelName, DataList = formDataList, SearchDataList = searchDataList, ContentDataList = contentDataList, ListViewDataList = tableDataList }; if (tableDataList.Count > 0)//生成列表视图 { content = Render <TempViewModel>("~/Template/ListViewTemp.cshtml", viewModel); System.IO.File.WriteAllText($"{viewPath}{modelName}List.cshtml", content, Encoding.UTF8); } //string content = GetResourceContent(listViewTxtPath).Replace("$column$", viewBuilder.ToString()).Replace("$modelname$", modelName); //System.IO.File.WriteAllText($"{viewPath}{modelName}List.cshtml", content, Encoding.UTF8); //string formText = formBuilder.ToString(); //content = GetResourceContent(listViewTxtPath).Replace("$column$", viewBuilder.ToString()).Replace("$modelname$", modelName).Replace("$formFields$", formText); //System.IO.File.WriteAllText($"{viewPath}Edit.cshtml", content, Encoding.UTF8); if (formDataList.Count > 0)//生成表单,详情视图 { content = Render <TempViewModel>("~/Template/EditViewTemp.cshtml", viewModel); System.IO.File.WriteAllText($"{viewPath}Edit.cshtml", content, Encoding.UTF8); content = Render <TempViewModel>("~/Template/DetailViewTemp.cshtml", viewModel); System.IO.File.WriteAllText($"{viewPath}Detail.cshtml", content, Encoding.UTF8); } }
/// <summary> /// 创建ViewModel文件 /// </summary> /// <param name="modelName"></param> /// <param name="fields"></param> public void GenerateViewModel(string modelName, List <string> fields) { List <string> searchList = fields.Where(m => m.StartsWith("search_")).ToList(); //搜索字段 List <string> fieldList = fields.Where(m => m.StartsWith("field_")).ToList(); //列表字段 List <string> formList = fields.Where(m => m.StartsWith("form_")).ToList(); //表单字段 List <Type> list = GetAllTypes("*.Repository.dll"); Type modelType = list.Where(u => u.Name == modelName).FirstOrDefault(); List <PropertyInfo> pros = modelType.GetProperties().ToList(); Dictionary <string, List <string> > dict = new Dictionary <string, List <string> > { { "searchList", searchList }, { "fieldList", fieldList }, { "formList", formList } }; foreach (KeyValuePair <string, List <string> > item in dict) { string content = ""; StringBuilder modelBuilder = new StringBuilder(); StringBuilder viewBuilder = new StringBuilder(); StringBuilder formBuilder = new StringBuilder(); List <string> searchDataList = new List <string>(); List <string> formDataList = new List <string>(); List <string> tableDataList = new List <string>(); foreach (string f in item.Value) { string fieldName = ""; if (item.Key == "searchList") { fieldName = f.Replace("search_", "").Trim(); } if (item.Key == "fieldList") { fieldName = f.Replace("field_", "").Trim(); } if (item.Key == "formList") { fieldName = f.Replace("form_", "").Trim(); } PropertyInfo pro = pros.Where(m => m.Name == fieldName).FirstOrDefault(); Type t = pro.PropertyType; string fieldType = "string"; string descriptionName = ""; DescriptionAttribute[] v = (DescriptionAttribute[])pro.GetCustomAttributes(typeof(DescriptionAttribute), false); if (v.Count() > 0) { string description = v[0].Description; descriptionName = description.Length > 0 ? description : fieldName; } if (CTS_Dict.ContainsKey(t.Name)) { fieldType = CTS_Dict[t.Name]; } //modelBuilder.Append("\r\n"); //modelBuilder.Append("/// <summary>\r\n"); //modelBuilder.Append($"///{descriptionName}\r\n"); //modelBuilder.Append("/// </summary>\r\n"); //modelBuilder.Append($"[Description(\"{descriptionName}\")] \r\n"); //modelBuilder.Append("public " + fieldType + " " + fieldName + " { get; set; } \r\n"); if (item.Key == "fieldList") { tableDataList.Add(fieldName + "," + descriptionName + "," + fieldType); } else if (item.Key == "formList") { formDataList.Add(fieldName + "," + descriptionName + "," + fieldType); } else if (item.Key == "searchList") { searchDataList.Add(fieldName + "," + descriptionName + "," + fieldType); } } if (!Directory.Exists(viewModelPath)) { Directory.CreateDirectory(viewModelPath); } if (searchDataList.Count > 0) { TempViewModel viewModel = new TempViewModel() { ProjectName = "CareerCRM", ControllerName = modelName, ModelName = modelName, DataList = searchDataList }; content = Render <TempViewModel>("~/Template/ReqModelTemp.cshtml", viewModel); content = content.Replace("<p>", "").Replace("</p>", ""); System.IO.File.WriteAllText($"{viewModelPath}{modelName}ListReq.cs", content, Encoding.UTF8); } if (tableDataList.Count > 0) { TempViewModel viewModel = new TempViewModel() { ProjectName = "CareerCRM", ControllerName = modelName, ModelName = modelName, DataList = tableDataList }; content = Render <TempViewModel>("~/Template/ListViewModelTemp.cshtml", viewModel); content = content.Replace("<p>", "").Replace("</p>", ""); System.IO.File.WriteAllText($"{viewModelPath}{modelName}ListVM.cs", content, Encoding.UTF8); } if (formDataList.Count > 0) { TempViewModel viewModel = new TempViewModel() { ProjectName = "CareerCRM", ControllerName = modelName, ModelName = modelName, DataList = formDataList }; content = Render <TempViewModel>("~/Template/FormDTOTemp.cshtml", viewModel); content = content.Replace("<p>", "").Replace("</p>", ""); System.IO.File.WriteAllText($"{viewModelPath}{modelName}FormDTO.cs", content, Encoding.UTF8); } } }
private JsonResult GetJsonResult(TempViewModel model) { JsonResult res = new JsonResult(); res.JsonRequestBehavior = JsonRequestBehavior.AllowGet; res.Data = model; return res; }
/// <summary> /// get temperature data starting at time and continuing for span with given period /// </summary> /// <param name="time">time in seconds</param> /// <param name="span">length of span in seconds</param> /// <param name="period"></param> /// <returns>JsonResult containing view model</returns> public JsonResult Get(double time, double span, int period) { var data = tempRepo.GetSamplesFromSpan(time, span, period); model = new TempViewModel(data); return GetJsonResult(model); }
/// <summary> /// get single sample by id /// </summary> public JsonResult Get(int id) { var data = tempRepo.GetById(id); model = new TempViewModel(data); return GetJsonResult(model); }
// GET api/<controller>?<time=''>&<span=''> /// <summary> /// get temperature data starting at time and continuing for a number of samples /// </summary> /// <param name="time">time in seconds</param> /// <param name="samples">number of samples</param> /// <returns>JsonResult containing view model</returns> public JsonResult Get(double time, int samples) { var data = tempRepo.GetSamplesFrom(time, samples); model = new TempViewModel(data); return GetJsonResult(model); }
// GET api/<controller> /// <summary> /// simple get all data from temperature table /// </summary> /// <returns>JsonResult containing view model</returns> public JsonResult Get() { var data = tempRepo.GetData(); model = new TempViewModel(data); return GetJsonResult(model); }
public static void ClearTemp() { _temp.Cleanup(); _temp = null; }
public static void CreateTemp() { if (_temp == null) { _temp = new TempViewModel(); } }
public static void ClearTemp() { _temp.Cleanup(); _temp = null; }