/// <summary> /// 添加表 /// </summary> /// <param name="model"></param> public void CreateTable(We7.Model.Core.ModelInfo model) { if (model.Type != ModelType.ARTICLE) { return; } string table = model.DataSet.Tables[0].Name; string sql = String.Format(SqlCreate, table); try { try { ModelDBHelper DbHelper = ModelDBHelper.Create(model.ModelName); //TODO:不知道以下代码作用是什么,看起来像是创建完表结构之后检测一下 DbHelper.Query(String.Format(SqlSelectTable, table)); } catch { ExecuteSql(sql); } } catch { } UpdateTable(model); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //清空缓存 Response.CacheControl = "no-cache"; Response.Expires = 0; if (Request["NewName"] != null && Request["NewID"] != null && Request["NewIDkey"] != null && Request["NewNamekey"] != null && Request["Model"] != null) { string newIDkey = Request["NewIDkey"].ToString(); string newNamekey = Request["NewNamekey"].ToString(); string newName = Request["NewName"].ToString(); string newID = Request["NewID"].ToString(); string model = Request["Model"].ToString(); ModelDBHelper helper = ModelDBHelper.Create(model); Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add(newNamekey, newName); if (newIDkey == "ID") { dic.Add(newIDkey, newID); } if (newIDkey != "ID" && newNamekey != "ID") { dic.Add("ID", newID); } dic.Add("AccountID", We7.CMS.Accounts.Security.CurrentAccountID); dic.Add("State", 1); dic.Add("Index", 999); dic.Add("Created", DateTime.Now); dic.Add("Updated", DateTime.Now); helper.Insert(dic); } } }
public override void InitControl() { hfValue.Value = lblValue.Text = (Value ?? "").ToString(); IAccountHelper accountHelper = AccountFactory.CreateInstance(); Account account = accountHelper.GetAccount(hfValue.Value, null); if (account == null) { ltlText.Text = ""; } else { string data = Control.Params[We7.Model.Core.UI.Constants.DATA]; if (!string.IsNullOrEmpty(data) && data == "admin") { //ShopPlugin.AdvanceUser DataTable dt = ModelDBHelper.Create("ShopPlugin.AdvanceUser").Query(new Criteria(CriteriaType.Equals, "UserID", hfValue.Value), new List <Order>() { new Order("ID", OrderMode.Desc) }, 0, 0); if (dt != null && dt.Rows.Count > 0) { ltlText.Text = "<a href='/admin/AddIns/ModelEditor.aspx?notiframe=1&model=ShopPlugin.AdvanceUser&ID=" + dt.Rows[0]["ID"].ToString() + "'>" + account.LoginName + "</a>"; } else { ltlText.Text = "<a href='/admin/Permissions/AccountEdit.aspx?id=" + account.ID + "'>" + account.LoginName + "</a>"; } } else { ltlText.Text = account.LoginName; } } }
public object Do(PanelContext data) { ModelDBHelper subHelper = ModelDBHelper.Create(data.ModelName); DataTable db = subHelper.Query(new Criteria(CriteriaType.Equals, "ID", data.DataKey.Value), new List <Order> { new Order("ID") }); DbProvider.Instance(data.Model.Type).Delete(data); foreach (We7Control ctrl in ModelHelper.GetPanelContext(data.ModelName, "edit").Panel.EditInfo.Controls) { if (!string.IsNullOrEmpty(ctrl.Params["count"])) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add(string.Format("{0}_Count", data.Model.Name), subHelper.Count(new Criteria(CriteriaType.Equals, ctrl.Name, db.Rows[0][ctrl.Name]))); ModelDBHelper helper = ModelDBHelper.Create(ctrl.Params["model"]); helper.Update(dic, new Criteria(CriteriaType.Equals, ctrl.Params["valuefield"], db.Rows[0][ctrl.Name])); } string fileurl = HttpContext.Current.Server.MapPath(db.Rows[0][ctrl.Name].ToString()); if (ctrl.Type == "MultiUploadify" && File.Exists(fileurl)) { File.Delete(fileurl); File.Delete(fileurl.Insert(fileurl.LastIndexOf('.'), "_thumb")); } } CacheRecord.Create(data.ModelName).Release(); return(null); }
public override void InitControl() { ddlEnum.PreRender += new EventHandler(ddlEnum_PreRender); string model = Control.Params["model"]; string valuefield = Control.Params["valuefield"]; string textfield = Control.Params["textfield"]; if (GeneralConfigs.GetConfig().EnableSingleTable) { ModelDBHelper helper = ModelDBHelper.Create(model); Criteria c = new Criteria(CriteriaType.Equals, "State", 1); DataTable dt = helper.Query(c, new List <Order>() { new Order("Created", OrderMode.Desc), new Order("ID", OrderMode.Desc) }, 0, 0); ddlEnum.DataSource = dt; } else { List <Article> list = ArticleHelper.QueryArticleByModel(model); DataSet ds = ModelHelper.CreateDataSet(model); foreach (Article a in list) { TextReader reader = new StringReader(a.ModelXml); ds.ReadXml(reader); } ddlEnum.DataSource = ds.Tables[0]; } ddlEnum.DataValueField = valuefield; ddlEnum.DataTextField = textfield; ddlEnum.DataBind(); ddlEnum.Items.Insert(0, new ListItem("请选择", "")); ddlEnum.SelectedValue = Value == null ? Control.DefaultValue : Value.ToString(); if (!String.IsNullOrEmpty(Control.Width)) { ddlEnum.Width = Unit.Parse(Control.Width); } if (!String.IsNullOrEmpty(Control.Height)) { ddlEnum.Height = Unit.Parse(Control.Height); } ddlEnum.CssClass = Control.CssClass; if (Control.Required && !ddlEnum.CssClass.Contains("required")) { ddlEnum.CssClass += " required"; } string urlParam = We7Helper.GetParamValueFromUrl(Request.RawUrl, Control.Name); if (!string.IsNullOrEmpty(urlParam)) { ddlEnum.SelectedValue = urlParam; } }
/// <summary> /// 执行操作 /// </summary> /// <param name="data"></param> /// <returns></returns> public object Do(PanelContext data) { ModelDBHelper subHelper = ModelDBHelper.Create(data.ModelName); List <DataKey> dataKeys = data.State as List <DataKey>; if (dataKeys.Count == 0) { return(null); } DataTable db = subHelper.Query(new Criteria(CriteriaType.Equals, "ID", dataKeys[0].Value), new List <Order> { new Order("ID") }); ModelDBHelper temhelper = null; string columnMapping = string.Empty; if (dataKeys != null) { foreach (We7DataColumn column in data.DataSet.Tables[0].Columns) { if (column.Name.Contains("_Count")) { temhelper = ModelDBHelper.Create(data.Model.GroupName + "." + column.Name.Remove(column.Name.IndexOf("_Count"))); columnMapping = column.Mapping; } } foreach (DataKey key in dataKeys) { if (temhelper != null) { DataTable dt = subHelper.Query(new Criteria(CriteriaType.Equals, "ID", key.Value), new List <Order> { new Order("ID") }); temhelper.Delete(new Criteria(CriteriaType.Equals, columnMapping.Split('|')[0], dt.Rows[0][columnMapping.Split('|')[1]])); } data.DataKey = key; DbProvider.Instance(data.Model.Type).Delete(data); } data.DataKey = null; } foreach (We7Control ctrl in ModelHelper.GetPanelContext(data.ModelName, "edit").Panel.EditInfo.Controls) { if (!string.IsNullOrEmpty(ctrl.Params["count"])) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add(string.Format("{0}_Count", data.Model.Name), subHelper.Count(new Criteria(CriteriaType.Equals, ctrl.Name, db.Rows[0][ctrl.Name]))); ModelDBHelper helper = ModelDBHelper.Create(ctrl.Params["model"]); helper.Update(dic, new Criteria(CriteriaType.Equals, ctrl.Params["valuefield"], db.Rows[0][ctrl.Name])); } string fileurl = HttpContext.Current.Server.MapPath(db.Rows[0][ctrl.Name].ToString()); if (ctrl.Type == "MultiUploadify" && File.Exists(fileurl)) { File.Delete(fileurl); File.Delete(fileurl.Insert(fileurl.LastIndexOf('.'), "_thumb")); } } CacheRecord.Create(data.ModelName).Release(); return(null); }
protected override void OnInitData() { Criteria c = CreateCriteria(); List <Order> os = CreateOrders(); ModelDBHelper dbhelper = ModelDBHelper.Create(ModelName); Items = dbhelper.QueryPagedList(c, os, 0, PageSize).Rows; }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); context.Response.Clear(); string action = context.Request["action"]; if (!String.IsNullOrEmpty(action)) { CategoryHelper helper = HelperFactory.Instance.GetHelper <CategoryHelper>(); string value = context.Request["value"]; action = action.Trim().ToLower(); List <Category> lsTemp = null; if (action == "seachcategory") { lsTemp = helper.GetChildrenListByKeyword(value); if (lsTemp != null && lsTemp.Count > 0) { StringBuilder sb = new StringBuilder(""); foreach (Category model in lsTemp) { sb.Append(model.KeyWord + "|" + model.Name + ","); } string result = ""; if (sb.Length > 1) { result = sb.ToString().TrimEnd(new char[] { ',' }); } context.Response.Write(result); return; } } else if (action == "seachbsfw") { DataTable dt = ModelDBHelper.Create("gov.bsfw").Query(new Criteria(CriteriaType.Equals, "yycj", value), new List <Order>() { new Order("ID") }, 0, 0); if (dt != null && dt.Rows.Count > 0) { StringBuilder sb = new StringBuilder(""); foreach (DataRow row in dt.Rows) { sb.Append(UrlHelper.GetModelUrl("gov.bsfw", row["ID"].ToString()) + "|" + row["ywmc"] + ","); } string result = ""; if (sb.Length > 1) { result = sb.ToString().TrimEnd(new char[] { ',' }); } context.Response.Write(result); return; } } } }
protected override void OnInitData() { int recordcount; ModelDBHelper dbhelper = ModelDBHelper.Create(ModelName); List <Order> os = CreateOrders(); Criteria c = CreateCriteria(); Items = dbhelper.QueryPagedList(c, os, Pager.PageIndex, Pager.PageSize, out recordcount).Rows; Pager.RecordCount = recordcount; }
/// <summary> /// 更新表 /// </summary> /// <param name="model"></param> public void UpdateTable(We7.Model.Core.ModelInfo model) { ModelDBHelper DbHelper = ModelDBHelper.Create(model.ModelName); string table = model.DataSet.Tables[0].Name; DataTable dt = DbHelper.Query(String.Format(SqlSelectTable, table)); We7DataColumnCollection columns = model.DataSet.Tables[0].Columns; if (!columns.Contains("Updated", true)) { columns.Add(new We7DataColumn() { DataType = TypeCode.DateTime, Name = "Updated" }); } if (!columns.Contains("AccountID", true)) { columns.Add(new We7DataColumn() { DataType = TypeCode.String, Name = "AccountID", MaxLength = 40 }); } foreach (We7DataColumn c in columns) { try { if (c.Direction == ParameterDirection.ReturnValue) { continue; } string sql = String.Empty; if (ContainsColumn(dt, c.Name)) { if (IgnoreUpdateFields.Contains(c.Name)) { continue; } sql = String.Format(SqlAlterColumn, table, c.Name, GetDbType(c)); } else { sql = String.Format(SqlAddColumn, table, c.Name, GetDbType(c)); } //DbHelper.Execute(sql); ExecuteSql(sql); } catch (Exception ex) { } } }
DataRow QueryRow(PanelContext ctx) { ModelDBHelper DbHelper = ModelDBHelper.Create(ctx.ModelName); Criteria c = new Criteria(CriteriaType.None); foreach (string key in ctx.DataKey.Values.Keys) { c.Add(CriteriaType.Equals, key, ctx.DataKey.Values[key]); } DataTable dt = DbHelper.Query(c, new List <Order>() { new Order("ID") }, 0, 0); return(dt != null && dt.Rows.Count > 0 ? dt.Rows[0] : null); }
public void ModelSort(string model, string data) { ModelDBHelper helper = ModelDBHelper.Create(model); Dictionary <string, object> dic = new Dictionary <string, object>(); foreach (string d in data.Split('|')) { string[] dd = d.Split(':'); if (dd.Length != 2) { continue; } dic.Clear(); dic.Add("Index", dd[1]); helper.Update(dic, new Criteria(CriteriaType.Equals, "ID", dd[0])); } }
public object Do(PanelContext data) { DbProvider.Instance(data.Model.Type).Insert(data); foreach (We7Control ctrl in data.Panel.EditInfo.Controls) { if (!string.IsNullOrEmpty(ctrl.Params["count"])) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add(string.Format("{0}_Count", data.Model.Name), ModelDBHelper.Create(data.ModelName).Count(new Criteria(CriteriaType.Equals, ctrl.Name, data.Row[ctrl.Name]))); ModelDBHelper helper = ModelDBHelper.Create(ctrl.Params["model"]); helper.Update(dic, new Criteria(CriteriaType.Equals, ctrl.Params["valuefield"], data.Row[ctrl.Name])); } } CacheRecord.Create(data.ModelName).Release(); return(null); }
protected override void OnInitData() { ModelDBHelper helper = ModelDBHelper.Create(ModelName); Criteria c = CreateEntryCriteria(); DataTable dt = helper.Query(CreateEntryCriteria(), CreateOrders(), 0, 0); Item = dt.Rows.Count > 0 ? dt.Rows[0] : dt.NewRow(); //更新点击次数 if (dt.Columns.Contains("Clicks")) { Dictionary <string, object> dic = new Dictionary <string, object>(); int clicks = Item["Clicks"].Equals(DBNull.Value) ? 0 : Convert.ToInt32(Item["Clicks"]); clicks++; dic.Add("Clicks", clicks); helper.Update(dic, c); } }
//测试2 protected override void OnLoad(EventArgs e) { ModelDBHelper helper = ModelDBHelper.Create("Subjects.Paper"); List <Order> os = new List <Order>(); os.Add(new Order("ID")); DataTable dt = helper.Query(new Criteria(CriteriaType.MoreThan, "Created", DateTime.MinValue), os, 0, 0); ArticleHelper ah = HelperFactory.Instance.GetHelper <ArticleHelper>(); foreach (DataRow row in dt.Rows) { Article a = new Article(); a.Icon = row["ID"].ToString(); a.OwnerID = row["OwnerID"].ToString(); a.State = 1; a.Title = row["Title"].ToString(); ah.AddArticle(a); } }
protected override void OnInitData() { ModelDBHelper helper = ModelDBHelper.Create(ModelName); Criteria c = CreateEntryCriteria(); DataTable dt = helper.Query(c, CreateOrders(), 0, 0, Fields); if (null != dt) { JoinEx joinex = new JoinEx(); MoldPanel mp = new MoldPanel(); ColumnInfoCollection columns = mp.GetPanelContext(ModelName, "list").Panel.ListInfo.Groups[0].Columns; foreach (ColumnInfo item in columns) { if (!string.IsNullOrEmpty(item.Params["model"])) { joinex.JoinInfo.Add(item.Name, new JoinEx() { MainField = item.Name, PriMaryKeyName = item.Params["valuefield"], ToField = item.Params["textfield"], ToTableName = item.Params["model"] }); } } if (joinex.JoinInfo != null && joinex.JoinInfo.Count > 0) { DataBaseAssistant db = new DataBaseAssistant(); dt = db.Join(dt, joinex); } } /*end*/ Item = dt != null && dt.Rows.Count > 0 ? dt.Rows[0] : dt.NewRow(); //更新点击次数 if (dt.Columns.Contains("Clicks")) { Dictionary <string, object> dic = new Dictionary <string, object>(); int clicks = Item["Clicks"].Equals(DBNull.Value) ? 0 : Convert.ToInt32(Item["Clicks"]); clicks++; dic.Add("Clicks", clicks); helper.Update(dic, c); } }
protected override void OnInitData() { Criteria c = CreateCriteria(); List <Order> os = CreateOrders(); ModelDBHelper dbhelper = ModelDBHelper.Create(ModelName); // Items = dbhelper.QueryPagedList(c, os, 0, PageSize).Rows; DataTable dt = dbhelper.QueryPagedList(c, os, 0, PageSize, Fields); /*begin 表关联相关*/ if (null != dt) { JoinEx joinex = new JoinEx(); MoldPanel mp = new MoldPanel(); ColumnInfoCollection columns = mp.GetPanelContext(ModelName, "list").Panel.ListInfo.Groups[0].Columns; foreach (ColumnInfo item in columns) { if (!string.IsNullOrEmpty(item.Params["model"])) { joinex.JoinInfo.Add(item.Name, new JoinEx() { MainField = item.Name, PriMaryKeyName = item.Params["valuefield"], ToField = item.Params["textfield"], ToTableName = item.Params["model"] }); } } if (joinex.JoinInfo != null && joinex.JoinInfo.Count > 0) { DataBaseAssistant db = new DataBaseAssistant(); dt = db.Join(dt, joinex); } } /*end*/ if (dt != null) { Items = dt.Rows; } }
private int GetSN(string preSN) { ModelDBHelper helper = ModelDBHelper.Create(PanelContext.ModelName); Criteria c = new Criteria(CriteriaType.Like, Control.Name, preSN + "%"); int count = helper.Count(c); if (count > 0) { DataTable dt = helper.Query(c, new List <Order> { new Order(Control.Name, OrderMode.Desc) }, 0, 1); string sn = dt.Rows[0][Control.Name].ToString(); string[] ss = sn.Split('-'); if (ss != null && ss.Length > 0) { int n; if (int.TryParse(ss[ss.Length - 1], out n)) { return(++n); } } } return(1); }