public string AddMapping(SQLTableInfo item) { if (item != null) { Type t = Keel.DB.Common.NowDataBase.PasteType(item.t_fieldtype); string fieldname = BaseGengerator.ClearBadChars(item.t_fieldname); string m = ""; #region 类型映射 string ext = ""; switch (Type.GetTypeCode(t)) { case TypeCode.Boolean: m = Mapping_Boolean; bool b = item.t_fielddefaultvalue.Contains("1"); m = m.Replace("_defaultvalue_", b.ToString()); ext = "chk"; break; case TypeCode.DBNull: break; case TypeCode.DateTime: m = Mapping_DateTime; string strxdt = item.t_fielddefaultvalue; if (strxdt.StartsWith("(") && strxdt.EndsWith(")")) { string[] ffdt = strxdt.Split("'".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (ffdt.Length >= 2) { strxdt = ffdt[1]; } } m = m.Replace("_defaultvalue_", strxdt); ext = "dte"; break; case TypeCode.Empty: break; case TypeCode.Char: case TypeCode.String: m = Mapping_String; string strx = item.t_fielddefaultvalue; if (strx.StartsWith("(") && strx.EndsWith(")")) { string[] ff = strx.Split("'".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (ff.Length >= 2) { strx = ff[1]; } } m = m.Replace("_defaultvalue_", strx); ext = "txt"; break; case TypeCode.Decimal: case TypeCode.Byte: case TypeCode.Double: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.SByte: case TypeCode.Single: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: m = Mapping_Decimal; decimal d; string bxf = ""; if (item.t_fielddefaultvalue != "" && decimal.TryParse(item.t_fielddefaultvalue.Replace("(", "").Replace(")", ""), out d)) { bxf = d.ToString(); } m = m.Replace("_defaultvalue_", bxf); ext = "dec"; break; case TypeCode.Object: default: m = Mapping_Unknow; m = m.Replace("_defaultvalue_", item.t_fielddefaultvalue); ext = "ukw"; break; } #endregion string _name_ = "keelctl_" + ext + "_" + fieldname; m = m.Replace("_name_", _name_); m = m.Replace("_desc_", item.t_fielddesc.Trim() != "" ? item.t_fielddesc : item.t_fieldname); m = m.Replace("_lenght_", item.t_fieldlenght.ToString()); m = m.Replace("_bitcount_", item.t_fieldbitcount.ToString()); CtlHtml.AppendLine(m); return(_name_); } else { return(null); } }
public static void DevXC(WinFormBaseGengerator wf, int dis, ref bool lr, ref int sum, ref int maxwinwidth, ref int maxwinheight, SQLTableInfo item) { sum++; IComponent iclbl = wf.AddControl(typeof( #if ENABLEDevExpress LabelControl #else Label #endif ), "lbl" + BaseGengerator.ClearBadChars(item.t_fieldname)); (iclbl as #if ENABLEDevExpress LabelControl #else Label #endif ).Text = ((item.t_fielddesc != null && item.t_fielddesc as string != "") ? item.t_fielddesc : item.t_fieldname) as string; IComponent ictxt; Type t = Keel.DB.Common.NowDataBase.PasteType(item.t_fieldtype); if (t.Equals(typeof(string))) { ictxt = wf.AddControl(typeof( #if ENABLEDevExpress TextEdit #else TextBox #endif ), "txt" + BaseGengerator.ClearBadChars(item.t_fieldname)); } else if (t.Equals(typeof(DateTime))) { ictxt = wf.AddControl(typeof( #if ENABLEDevExpress DateEdit #else DateTimePicker #endif ), "dtp" + BaseGengerator.ClearBadChars(item.t_fieldname)); } else if (t.Equals(typeof(decimal)) || t.Equals(typeof(Int32)) || t.Equals(typeof(float)) || t.Equals(typeof(double)) || t.Equals(typeof(byte)) || t.Equals(typeof(int)) || t.Equals(typeof(Int16)) || t.Equals(typeof(Int64)) ) { ictxt = wf.AddControl(typeof( #if ENABLEDevExpress SpinEdit #else NumericUpDown #endif ), "nud" + BaseGengerator.ClearBadChars(item.t_fieldname)); } else { ictxt = wf.AddControl(typeof( #if ENABLEDevExpress TextEdit #else TextBox #endif ), "txt_unsupport_type_" + BaseGengerator.ClearBadChars(item.t_fieldname)); } int y; int xxx = Math.DivRem(sum, 2, out y) + y; // (ictxt as Control).Tag = item.t_fieldname; (ictxt as Control).TabIndex = (int)item.t_fieldindex; switch (lr) { default: case true: (iclbl as #if ENABLEDevExpress LabelControl #else Label #endif ).Location = new Point(20 + 300, dis * xxx); (ictxt as Control).Location = new Point(20 + 300 + (iclbl as #if ENABLEDevExpress LabelControl #else Label #endif ).Width + dis, dis * xxx); int fw = (ictxt as Control).Left + (ictxt as Control).Width; int fh = (ictxt as Control).Top + (ictxt as Control).Height; maxwinwidth = maxwinwidth > fw ? maxwinwidth : fw; maxwinheight = maxwinheight > fh ? maxwinheight : fh; lr = false; break; case false: (iclbl as #if ENABLEDevExpress LabelControl #else Label #endif ).Location = new Point(20, dis * xxx); (ictxt as Control).Location = new Point(20 + (iclbl as #if ENABLEDevExpress LabelControl #else Label #endif ).Width + dis, dis * xxx); lr = true; break; } }