//[System.Diagnostics.Conditional("XPO")] private void XPOClassDesignerFileWrite(Tables tbl) { if (rdbXpo.Checked == false) { return; } string tabs = ""; using (FileHelper w = new FileHelper(txtpath.Text + "\\" + tbl.ModulName + "\\" + tbl.TableName + ".Designer.cs")) { w.WriteLine("using System;"); w.WriteLine("using System.Text;"); w.WriteLine("using System.Linq;"); w.WriteLine("using DevExpress.Xpo;"); w.WriteLine("using System.ComponentModel;"); w.WriteLine("using System.Xml.Serialization;"); w.WriteLine("using System.Collections.Generic;"); w.WriteLine("using System.Runtime.InteropServices;"); w.WriteLine(""); w.WriteLine("namespace " + txtnamespace.Text); w.WriteLine("{"); tabs = "\t"; w.WriteLine(tabs + "[DeferredDeletion(false)]"); w.WriteLine(tabs + "[OptimisticLocking(false)]"); w.WriteLine(tabs + "[Persistent(\"" + tbl.Name + "\")]"); w.WriteLine(tabs + "public partial class " + tbl.TableName); w.WriteLine(tabs + "{"); w.WriteLine(""); tabs = "\t\t"; w.WriteLine(tabs + "public " + tbl.TableName + "() { }"); w.WriteLine(tabs + ""); w.WriteLine(tabs + "public " + tbl.TableName + "(Session session) : base(session) { }"); w.WriteLine(tabs + ""); for (int i = 0; i < tbl.Columns.Count; i++) { w.WriteLine(tabs + "private " + Fields.ToCScrap(tbl.Columns[i].ColumnDataType) + " f" + tbl.Columns[i].FieldName + " = " + Fields.CScrapDefaultValue(tbl.Columns[i].ColumnDataType) + ";"); w.WriteLine(tabs + tbl.Columns[i].ToColumnXPOLenght()); if (tbl.Columns[i].IsPrimaryKey) { w.WriteLine(tabs + "[Key(AutoGenerate = true)]"); } w.WriteLine(tabs + "[Persistent(\"" + tbl.Columns[i].Name + "\")]"); if (tbl.Columns[i].ColumnCScrapType == "bool") { w.WriteLine(tabs + "[DbType(\"int2 DEFAULT 0\")]"); w.WriteLine(tabs + "[ValueConverter(typeof(WarehouseManagementDictionary.BoolConverter))]"); } w.WriteLine(tabs + "public " + tbl.Columns[i].ColumnCScrapType + " " + tbl.Columns[i].FieldName); w.WriteLine(tabs + "{"); w.WriteLine(tabs + "\tget { return f" + tbl.Columns[i].FieldName + "; }"); w.WriteLine(tabs + "\tset { SetPropertyValue<" + tbl.Columns[i].ColumnCScrapType + ">(\"" + tbl.Columns[i].FieldName + "\", ref f" + tbl.Columns[i].FieldName + ", value); }"); w.WriteLine(tabs + "}"); w.WriteLine(""); } w.WriteLine(""); w.WriteLine("\t}"); w.WriteLine("}"); } }
private void Tables() { comm.Parameters.Clear(); comm.CommandText = "SELECT * FROM [Tablo Listesi$]"; OleDbDataAdapter adapter = new OleDbDataAdapter(comm); DataTable dt = new DataTable(); adapter.Fill(dt); int order = 1, orderClm = 1; string modul, type, tablename; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { orderClm = 1; string name = dt.Rows[i][1].ToString(); if (!string.IsNullOrEmpty(name)) { modul = name.Substring(0, 3).ToUpper(CultureInfo.CreateSpecificCulture("en-US")); if (BusinessObjects.Tables.modules.Contains(modul) && name.IndexOf("_") != -1) { type = name.Substring(3, 1); tablename = Utility.TextInfo.ToTitleCase(name.Substring(5, name.Length - 5)).Replace('_', ' ').Replace(" ", String.Empty); } else { modul = ""; type = ""; tablename = Utility.TextInfo.ToTitleCase(name).Replace('_', ' ').Replace(" ", String.Empty); } Tables tbl = XpoDefault.Session.FindObject <Tables>(CriteriaOperator.Parse("Name = ?", name)); if (tbl == null) { tbl = new BusinessObjects.Tables(XpoDefault.Session); } try { if (excelTables.Contains(name)) { comm.CommandText = string.Format("SELECT * FROM [{0}$]", name); OleDbDataAdapter adapterColm = new OleDbDataAdapter(comm); DataTable dtClm = new DataTable(); adapterColm.Fill(dtClm); if (dtClm != null && dtClm.Rows.Count > 0) { for (int l = 0; l < dtClm.Rows.Count; l++) { string nameClm = dtClm.Rows[l][1].ToString(); if (!string.IsNullOrEmpty(nameClm)) { Fields clm = XpoDefault.Session.FindObject <Fields>(CriteriaOperator.Parse("Name = ? And Table = ?", nameClm, tbl)); if (clm == null) { clm = new BusinessObjects.Fields(XpoDefault.Session); } clm.Table = tbl; clm.Order = orderClm; clm.Name = dtClm.Rows[l][1].ToString(); clm.FieldName = Utility.TextInfo.ToTitleCase(clm.Name).Replace('_', ' ').Replace(" ", String.Empty); clm.ColumnDataType = dtClm.Rows[l][2].ToString().ToLower(); clm.ColumnCScrapType = Fields.ToCScrap(dtClm.Rows[l][2].ToString().ToLower()); clm.ColumnCScrapDefaultValue = Fields.CScrapDefaultValue(dtClm.Rows[l][2].ToString().ToLower()); clm.Description = dtClm.Rows[l][3].ToString(); clm.IsPrimaryKey = dtClm.Rows[l][4].ToString() != ""; clm.IsRequired = dtClm.Rows[l][5].ToString() != ""; tbl.Columns.Add(clm); orderClm++; } } } } } catch (Exception exc) { } tbl.Order = order; tbl.Name = dt.Rows[i][1].ToString(); tbl.ModulName = modul; tbl.TableType = type; tbl.TableName = tablename; tbl.Description = dt.Rows[i][2].ToString(); tbl.Prefix = dt.Rows[i][3].ToString(); if (XpoDefault.Session.IsNewObject(tbl)) { BusinessObjects.Fields clmcreateuser = new BusinessObjects.Fields(XpoDefault.Session); clmcreateuser.Table = tbl; clmcreateuser.Order = orderClm; clmcreateuser.Name = "create_user_id"; clmcreateuser.FieldName = Utility.TextInfo.ToTitleCase("create_user_id").Replace('_', ' ').Replace(" ", String.Empty); clmcreateuser.ColumnDataType = "integer"; clmcreateuser.ColumnCScrapType = Fields.ToCScrap("integer"); clmcreateuser.ColumnCScrapDefaultValue = Fields.CScrapDefaultValue("integer"); clmcreateuser.Description = ""; clmcreateuser.IsPrimaryKey = false; clmcreateuser.IsRequired = false; tbl.Columns.Add(clmcreateuser); orderClm++; BusinessObjects.Fields clmcreatedate = new BusinessObjects.Fields(XpoDefault.Session); clmcreatedate.Table = tbl; clmcreatedate.Order = orderClm; clmcreatedate.Name = "create_date"; clmcreatedate.FieldName = Utility.TextInfo.ToTitleCase("create_date").Replace('_', ' ').Replace(" ", String.Empty); clmcreatedate.ColumnDataType = "timestamp"; clmcreatedate.ColumnCScrapType = Fields.ToCScrap("timestamp"); clmcreatedate.ColumnCScrapDefaultValue = Fields.CScrapDefaultValue("timestamp"); clmcreatedate.Description = ""; clmcreatedate.IsPrimaryKey = false; clmcreatedate.IsRequired = false; tbl.Columns.Add(clmcreatedate); orderClm++; BusinessObjects.Fields clmupdateuser = new BusinessObjects.Fields(XpoDefault.Session); clmupdateuser.Table = tbl; clmupdateuser.Order = orderClm; clmupdateuser.Name = "update_user_id"; clmupdateuser.FieldName = Utility.TextInfo.ToTitleCase("update_user_id").Replace('_', ' ').Replace(" ", String.Empty); clmupdateuser.ColumnDataType = "integer"; clmupdateuser.ColumnCScrapType = Fields.ToCScrap("integer"); clmupdateuser.ColumnCScrapDefaultValue = Fields.CScrapDefaultValue("integer"); clmupdateuser.Description = ""; clmupdateuser.IsPrimaryKey = false; clmupdateuser.IsRequired = false; tbl.Columns.Add(clmupdateuser); orderClm++; BusinessObjects.Fields clmupdatedate = new BusinessObjects.Fields(XpoDefault.Session); clmupdatedate.Table = tbl; clmupdatedate.Order = orderClm; clmupdatedate.Name = "update_date"; clmupdatedate.FieldName = Utility.TextInfo.ToTitleCase("update_date").Replace('_', ' ').Replace(" ", String.Empty); clmupdatedate.ColumnDataType = "timestamp"; clmupdatedate.ColumnCScrapType = Fields.ToCScrap("timestamp"); clmupdatedate.ColumnCScrapDefaultValue = Fields.CScrapDefaultValue("timestamp"); clmupdatedate.Description = ""; clmupdatedate.IsPrimaryKey = false; clmupdatedate.IsRequired = false; tbl.Columns.Add(clmupdatedate); orderClm++; tbl.Save(); } this.innerList.Add(tbl); order++; } else { break; } } this.innerList.TrimExcess(); } }