/// <summary> /// this.gv_TABLE.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] { this.COMMENTS}) /// </summary> /// <returns></returns> public string GvColumnSetScript(DataTable dt, string gvName) { StringBuilder sb = new StringBuilder(); StringBuilder sbRes = new StringBuilder(); string res = string.Empty; if (ExDtMethod.GetRowCount(dt) > 0) { int index = 0; foreach (DataRow row in dt.Rows) { if (index < dt.Rows.Count - 1) { sb.AppendFormat("this.{0},", Convert.ToString(row["NAME"])); sb.AppendLine(); } else { sb.AppendFormat("this.{0}", Convert.ToString(row["NAME"])); } index++; } res = sb.ToString(); } string returnStr = "this." + gvName + ".Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {" + res + "});"; return(returnStr); }
public string FiledConvert2Dt(DataTable dt, string dtName = "dtInfo") { StringBuilder sb = new StringBuilder(); if (ExDtMethod.GetRowCount(dt) > 0) { foreach (DataRow row in dt.Rows) { if (row != null) { string filed = Convert.ToString(row["COLUMN_NAME"]); string filedRemark = Convert.ToString(row["COMMENTS"]); string type = Convert.ToString(row["DATA_TYPE"]); if (type.Equals("NUMBER")) { sb.AppendFormat(@"{0}.Columns.Add({1},typeof({2}));{3}", dtName, "\"" + filed.Trim() + "\"", "double", string.IsNullOrWhiteSpace(filedRemark) ? string.Empty : "//" + filedRemark); } else { sb.AppendFormat(@"{0}.Columns.Add({1});{2}", dtName, "\"" + filed.Trim() + "\"", string.IsNullOrWhiteSpace(filedRemark) ? string.Empty : "//" + filedRemark); } } sb.AppendLine(); } } return(sb.ToString()); }
/// <summary> /// 检查表是否存在,存在则不创建,不存在则创建 /// </summary> /// <param name="tableName"></param> public static void CheckOrCreateTable(string tableName, DataTable dt) { DataTable dtExists = sqlLite.ValidateIsTable(tableName); if (ExDtMethod.GetRowCount(dtExists) > 0 && dtExists.Rows[0]["CNT"].ToString() == "0") { sqlLite.AddNewTable(dt, tableName); } }
/// <summary> /// ComboBoxEdit 填加对应的值 /// </summary> /// <param name="dt"></param> /// <param name="combox"></param> public static void AddItemToComboxEdit(DataTable dt, ComboBoxEdit combox, string filedName, int selectIndex = 0) { if (ExDtMethod.GetRowCount(dt) > 0) { foreach (DataRow row in dt.Rows) { string value = Convert.ToString(row[filedName]); AddItemToComboxEdit(value, combox); } combox.SelectedIndex = selectIndex; } }
/// <summary> /// this.COMMENTS = new DevExpress.XtraGrid.Columns.GridColumn(); /// </summary> /// <returns></returns> public string NewObjectScirpt(DataTable dt) { StringBuilder sb = new StringBuilder(); if (ExDtMethod.GetRowCount(dt) > 0) { foreach (DataRow row in dt.Rows) { sb.AppendFormat(" this.{0} = new DevExpress.XtraGrid.Columns.GridColumn();", Convert.ToString(row["NAME"])); sb.AppendLine(); } } return(sb.ToString()); }
/// <summary> /// 列的配置 /// </summary> /// <returns></returns> public string ColumnConfigScript(DataTable dt) { StringBuilder sb = new StringBuilder(); if (ExDtMethod.GetRowCount(dt) > 0) { foreach (DataRow row in dt.Rows) { sb.AppendFormat("//"); sb.AppendLine(); sb.AppendFormat("//{0}", Convert.ToString(row["NAME"])); sb.AppendLine(); sb.AppendFormat("//"); sb.AppendLine(); sb.AppendFormat("{0}.AppearanceHeader.Options.UseTextOptions = true;", Convert.ToString(row["NAME"])); sb.AppendLine(); sb.AppendFormat("{0}.Width = {1};", Convert.ToString(row["NAME"]), Convert.ToInt32(row["WIDTH"])); sb.AppendLine(); sb.AppendFormat("{0}.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;", Convert.ToString(row["NAME"])); sb.AppendLine(); sb.AppendFormat("{0}.Caption = {1};", Convert.ToString(row["NAME"]), '"' + Convert.ToString(row["CAPTION"]) + '"'); sb.AppendLine(); sb.AppendFormat("{0}.FieldName = {1};", Convert.ToString(row["NAME"]), '"' + Convert.ToString(row["FILEDNAME"]) + '"'); sb.AppendLine(); sb.AppendFormat("{0}.Name = {1};", Convert.ToString(row["NAME"]), '"' + Convert.ToString(row["NAME"]) + '"'); sb.AppendLine(); if (Convert.ToBoolean(row["IsVisible"])) { sb.AppendFormat("{0}.Visible = {1};", Convert.ToString(row["NAME"]), Convert.ToBoolean(row["IsVisible"]).ToString().ToLower()); sb.AppendLine(); } sb.AppendFormat("{0}.VisibleIndex = {1};", Convert.ToString(row["NAME"]), Convert.ToInt32(row["VISIBLEINDEX"])); sb.AppendLine(); } } return(sb.ToString()); }