/// <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); }
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); }
/// <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); }
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="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); }
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); } }
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); }