示例#1
0
		public void Write(){
			
			if(string.IsNullOrEmpty(AppName)) AppName="App";
			
			if(string.IsNullOrEmpty(Define))
				Define= string.Format("{0}.view.{1}.List",AppName,type.Name.ToLower());
						
			if(string.IsNullOrEmpty(Extend))
				Extend= Config.List;
			
			if(string.IsNullOrEmpty(Alias))
				Alias= string.Format("widget.{0}list",type.Name.ToLower());
			
			if(string.IsNullOrEmpty(Store))
				Store= string.Format(type.Name);
			
			
			
			List<ListColumn> cols = new List<ListColumn>();
			
			foreach(PropertyInfo pi in type.GetProperties()){
				
				if(pi.Name== OrmLiteConfig.IdField) continue;
				
				ListColumn col = new ListColumn();
				col.text=string.Format("'{0}'", pi.Name);
				col.dataIndex= string.Format("'{0}'", pi.Name);
				col.sortable= true;
				if (cols.Count==0)  col.flex= 1;
				
				if(pi.PropertyType== typeof(DateTime) || pi.PropertyType== typeof(DateTime?))
				{
					col.renderer="Ext.util.Format.dateRenderer('d.m.Y')";
				}
				else if(pi.PropertyType== typeof(Int16) || pi.PropertyType== typeof(Int16?)
				        || pi.PropertyType== typeof(Int32) || pi.PropertyType== typeof(Int32?)
				        || pi.PropertyType== typeof(Int64) || pi.PropertyType== typeof(Int64?))
				{
					col.renderer="<FormatInt/>";
				}
				else if(pi.PropertyType== typeof(decimal) || pi.PropertyType== typeof(decimal?)
				        || pi.PropertyType== typeof(double) || pi.PropertyType== typeof(double?)
				        || pi.PropertyType== typeof(float) || pi.PropertyType== typeof(float?))
				{
					col.renderer="<FormatNumber/>";
				}
				else if(pi.PropertyType== typeof(bool) || pi.PropertyType== typeof(bool?))
				{
					col.xtype="'booleancolumn'";
					col.trueText= "'Si'";
					col.falseText= "'No'";
					col.align="'center'";
				}
				
				cols.Add(col);
			}
			
			string sCols= cols.SerializeAndFormat().
				Replace("<FormatInt/>", Config.FormatInt).
			    Replace("<FormatNumber/>", Config.FormatNumber).
				Replace("True","true").
				Replace("False","false");
			
			if(string.IsNullOrEmpty(OutputDirectory))
				OutputDirectory= Path.Combine(Directory.GetCurrentDirectory(), "modules");				
			
			if (!Directory.Exists(OutputDirectory))
					Directory.CreateDirectory(OutputDirectory);
			
			string viewDir = Path.Combine(Path.Combine(OutputDirectory, Config.ViewDirectory),type.Name.ToLower());				
			
			if (!Directory.Exists(viewDir))
					Directory.CreateDirectory(viewDir);
						
			if(string.IsNullOrEmpty(FileName))
				FileName= "List.js";
			
			
			using (TextWriter tw = new StreamWriter(Path.Combine(viewDir, FileName)))
			{
				tw.Write(string.Format(template, Define, Extend, Alias, Store, sCols));
				tw.Close();
			}
			
		}
示例#2
0
		public void Write()
		{
			if(string.IsNullOrEmpty(AppName)) AppName="App";
			
			if(string.IsNullOrEmpty(Define))
				Define= string.Format("{0}.view.{1}.Form",AppName, type.Name.ToLower());
						
			if(string.IsNullOrEmpty(Extend))
				Extend= Config.Form;
			
			if(string.IsNullOrEmpty(Alias))
				Alias= string.Format("widget.{0}form",type.Name.ToLower());
			
			
			List<FormItem> items= new List<FormItem>();
			
			foreach(PropertyInfo pi in type.GetProperties())
			{
				FormItem item = new FormItem();
				item.name= string.Format("'{0}'",pi.Name);
				if(pi.Name== OrmLiteConfig.IdField)
				{
					item.xtype="'hidden'";
					items.Add(item);
					continue; 
				}
				
				item.fieldLabel=string.Format("'{0}'",pi.Name);
				
				if(!pi.PropertyType.ToString().StartsWith("System.Nullable") && pi.PropertyType!=typeof(string) )
				   item.allowBlank=false;
				   
				if( pi.PropertyType == typeof(string) )
				{
					RequiredAttribute ra = pi.FirstAttribute<RequiredAttribute>();
					if(ra != null)
					{
						item.allowBlank=false;
					}
					
					StringLengthAttribute la = pi.FirstAttribute<StringLengthAttribute>();
					if( la !=null )
					{
						item.maxLength= la.MaximumLength;
						item.enforceMaxLength=true;
					}
					if(pi.Name.ToUpper().Contains("MAIL") || pi.Name.ToUpper().Contains("CORREO"))
						item.vtype="'email'";
				}
				else if( pi.PropertyType == typeof(DateTime) || pi.PropertyType == typeof(DateTime?))
				{
					item.xtype="'datefield'";
					item.format="'d.m.Y'";
				}
				else if(pi.PropertyType== typeof(Int16) || pi.PropertyType== typeof(Int16?)
				        || pi.PropertyType== typeof(Int32) || pi.PropertyType== typeof(Int32?)
				        || pi.PropertyType== typeof(Int64) || pi.PropertyType== typeof(Int64?))
				{
					item.xtype="'numberfield'";
					item.allowDecimals=false;
				}
				else if(pi.PropertyType== typeof(decimal) || pi.PropertyType== typeof(decimal?)
				        || pi.PropertyType== typeof(double) || pi.PropertyType== typeof(double?)
				        || pi.PropertyType== typeof(float) || pi.PropertyType== typeof(float?))
				{
					item.xtype="'numberfield'";
				}
				else if(pi.PropertyType==typeof(bool) || pi.PropertyType==typeof(bool?))
				{
					item.xtype="'checkboxfield'";
				}
				
				items.Add(item);
			}
			
			int height = 90;
			
			int ic= items.Count(i=>i.xtype!="'hidden'");
			
			if(ic==2) height=145;
			else if (ic==3) height=150;
			else if (ic==4) height=170;
			else if (ic>=5) height=40*ic;
			if( height>350) height=350;
			
			string sItems= items.SerializeAndFormat().Replace("True","true").Replace("False","false");

			if(string.IsNullOrEmpty(OutputDirectory))
				OutputDirectory= Path.Combine(Directory.GetCurrentDirectory(), "modules");				
			
			if (!Directory.Exists(OutputDirectory))
					Directory.CreateDirectory(OutputDirectory);
			
			string viewDir = Path.Combine(Path.Combine(OutputDirectory, Config.ViewDirectory),type.Name.ToLower());				
			
			if (!Directory.Exists(viewDir))
					Directory.CreateDirectory(viewDir);
			
			if(string.IsNullOrEmpty(FileName))
				FileName= "Form.js";
			
				
			using (TextWriter tw = new StreamWriter(Path.Combine(viewDir, FileName)))
			{
				tw.Write(string.Format(template, Define, Extend, Alias, sItems, height));
				tw.Close();
			}
			
			
		}