Ejemplo n.º 1
0
        /// <summary>
        ///  将当前更改保存到数据库
        /// </summary>
        /// <returns></returns>
        public int SaveChange()
        {
            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }

            CheckNotNull.NotEmpty(this.WhereList, "The delete operation must specify where conditions!");

            this.ToString();
            var affrows = 0;

            try
            {
                affrows = base.ExecuteNonQuery(this.CommandText);
            }
            finally
            {
                base.ParamList.Clear();
            }

            return(affrows);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  将当前更改保存到数据库
        /// </summary>
        /// <returns></returns>
        public int SaveChange()
        {
            string tableName = MyStagingUtils.GetMapping(typeof(T));

            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }
            string cmdText = $"UPDATE {tableName} SET {string.Join(",", this.setList)} {"WHERE " + string.Join("\nAND ", WhereList)}";
            int    affrows = 0;

            if (OnChanged != null)
            {
                cmdText += " RETURNING *;";

                var objList = base.ByMaster().ExecuteReader <T>(cmdText);
                affrows = objList.Count;
                if (affrows > 0 && this.OnChanged != null)
                {
                    OnChanged(objList[0]);
                }
            }
            else
            {
                affrows = base.ExecuteNonQuery(cmdText);
            }

            return(affrows);
        }
Ejemplo n.º 3
0
        //Constructor
        //Init' property values

        public EntryObject()
        {
            EntryID = -1;
            NameList.Add("_null");
            TypeList.Add("_null");
            WhereList.Add("_null");
            ExtraList.Add("_null");
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  该方法没有对sql注入进行参数化过滤
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public QueryContext <T> Where(string expression)
        {
            if (string.IsNullOrEmpty(expression))
            {
                throw new ArgumentNullException("必须传递参数 expression");
            }

            WhereList.Add(expression);
            return(this);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///  将当前更改保存到数据库
        /// </summary>
        /// <returns></returns>
        public int SaveChange()
        {
            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }

            if (this.setList.Count == 0)
            {
                throw new ArgumentException("fields to be updated must be provided!");
            }

            if (this.WhereList.Count == 0)
            {
                throw new ArgumentException("The update operation must specify where conditions!");
            }

            this.ToString();

            int affrows = 0;

            if (OnChanged != null)
            {
                this.CommandText += " RETURNING *;";

                var objList = base.ByMaster().ExecuteReader <T>(this.CommandText);
                affrows = objList.Count;
                if (affrows > 0 && this.OnChanged != null)
                {
                    OnChanged(objList[0]);
                }
            }
            else
            {
                affrows = base.ExecuteNonQuery(this.CommandText);
            }

            return(affrows);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///  增加查询条件
        /// </summary>
        /// <param name="formatCommad">格式为{0}{1}的字符串</param>
        /// <param name="pValue">{0}{1}对应的值</param>
        /// <returns></returns>
        public QueryContext <T> Where(string formatCommad, params object[] pValue)
        {
            if (pValue == null || pValue.Length == 0)
            {
                throw new ArgumentNullException("必须传递参数 pValue");
            }
            List <object> nameList = new List <object>();

            foreach (var item in pValue)
            {
                string name = Guid.NewGuid().ToString("N");
                this.AddParameter(name, item);
                nameList.Add("@" + name);
            }
            formatCommad = string.Format(formatCommad, nameList.ToArray());
            WhereList.Add(formatCommad);
            return(this);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  将当前更改保存到数据库
        /// </summary>
        /// <returns></returns>
        public int SaveChange()
        {
            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }

            if (this.WhereList.Count == 0)
            {
                throw new ArgumentException("The delete operation must specify where conditions!");
            }

            this.ToString();

            return(base.ExecuteNonQuery(this.CommandText));
        }
Ejemplo n.º 8
0
        /// <summary>
        ///  将当前更改保存到数据库
        /// </summary>
        /// <returns></returns>
        public int SaveChange()
        {
            string tableName = MyStagingUtils.GetMapping(typeof(T));

            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    //PgSqlExpression expression = new PgSqlExpression();
                    //expression.ExpressionCapture(item.Body);
                    //WhereList.Add(expression.CommandText.ToString().ToLower());
                    //ParamList.AddRange(expression.Parameters);

                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }
            string cmdText = $"DELETE FROM {tableName} {"WHERE " + string.Join("\nAND ", WhereList)}";

            return(base.ExecuteNonQuery(cmdText));
        }
Ejemplo n.º 9
0
 public WhereList OR(IPhrase phrase, WhereComparison comparison, string tableName, string columnName)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(phrase, comparison, tableName, columnName);
 }
Ejemplo n.º 10
0
 public void WhereAdd(params object[] Degerler)
 {
     WhereList.Add(SqlExperOperatorIslem.WhereAdd(Degerler));
 }
Ejemplo n.º 11
0
 public void WhereAdd(CAR003E Property, Operand In_NotIn, params object[] Degerler_Parantez)
 {
     WhereList.Add(SqlExperOperatorIslem.WhereAdd(Enum.GetName(typeof(CAR003E), Property), In_NotIn, Degerler_Parantez));
 }
Ejemplo n.º 12
0
 public void WhereAdd(CAR003E Property, Islem islem, object Deger, Operand And_Or = Operand.AND)
 {
     WhereList.Add(SqlExperOperatorIslem.WhereAdd(Enum.GetName(typeof(CAR003E), Property), islem, Deger, And_Or));
 }
Ejemplo n.º 13
0
 public WhereList OR(string columnName, object betweenValue, object andValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(columnName, betweenValue, andValue);
 }
Ejemplo n.º 14
0
 public WhereList OR(string tableName, string columnName, WhereComparison comparison, string otherTableName, string otherColumnName)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(tableName, columnName, comparison, otherTableName, otherColumnName);
 }
Ejemplo n.º 15
0
 public void WhereAdd(EvrakIniE Property, object Deger, Operand And_Or = Operand.AND)
 {
     WhereList.Add(SqlExperOperatorIslem.WhereAdd(Enum.GetName(typeof(EvrakIniE), Property), Deger, And_Or));
 }
Ejemplo n.º 16
0
        /// <summary>
        ///  将查询命令和条件转换为 SQL 语句
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            Type   mastertype = typeof(T);
            string tableName  = MyStagingUtils.GetMapping(mastertype);
            // master table
            StringBuilder sqlText = new StringBuilder();

            sqlText.AppendLine($"SELECT {string.Join(",", Fields)} FROM  {tableName} {masterAlisName}");
            // union
            int _index = 2;

            foreach (var item in UnionList)
            {
                DbExpressionVisitor expression = new DbExpressionVisitor
                {
                    TypeMaster  = item.MasterType,
                    AliasMaster = item.AlisName,
                    AliasUnion  = item.UnionAlisName
                };
                expression.Visit(item.Body);
                string unionTableName = MyStagingUtils.GetMapping(item.Model);
                sqlText.AppendLine(item.UnionType.ToString().Replace("_", " ") + " " + unionTableName + " " + expression.AliasUnion + " ON " + expression.SqlText.Builder.ToString());
                ParamList.AddRange(expression.SqlText.Parameters);
                _index++;
            }
            // condition
            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    if (UnionList.Count == 0)
                    {
                        expression.TypeMaster  = item.Model;
                        expression.AliasMaster = masterAlisName;
                    }
                    else
                    {
                        ExpressionUnionModel union = null;
                        if (item.UnionAlisName == null)
                        {
                            union = UnionList.FirstOrDefault(f => f.Model == item.Model);
                        }
                        else
                        {
                            union = UnionList.FirstOrDefault(f => f.Model == item.Model && f.UnionAlisName == item.UnionAlisName);
                        }

                        if (union == null && typeof(T) == item.Model)
                        {
                            expression.TypeMaster  = item.Model;
                            expression.AliasMaster = masterAlisName;
                        }
                        else if (union != null)
                        {
                            expression.AliasMaster = union.AlisName;
                            expression.AliasUnion  = union.UnionAlisName;
                        }
                        else
                        {
                            throw new NotSupportedException($"找不到 where {item.Body.ToString()}条件的表,不支持的表查询条件");
                        }
                    }
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }

            if (WhereList.Count > 0)
            {
                sqlText.AppendLine("WHERE " + string.Join("\nAND ", WhereList));
            }
            if (!string.IsNullOrEmpty(GroupByText))
            {
                sqlText.AppendLine(GroupByText);
            }
            if (!string.IsNullOrEmpty(GroupByText) && !string.IsNullOrEmpty(HavingText))
            {
                sqlText.AppendLine(HavingText);
            }
            if (!string.IsNullOrEmpty(OrderByText))
            {
                sqlText.AppendLine(OrderByText);
            }
            if (!string.IsNullOrEmpty(LimitText))
            {
                sqlText.AppendLine(LimitText);
            }

            this.commandtext = sqlText.ToString();

            return(this.commandtext);
        }
Ejemplo n.º 17
0
 public WhereList OR(IPhrase phrase)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(phrase);
 }
Ejemplo n.º 18
0
 public void WhereAdd(CAR005E Property, object deger, Operand and_Or = Operand.AND)
 {
     WhereList.Add(SqlExperOperatorIslem.WhereAdd(Enum.GetName(typeof(CAR005E), Property), deger, and_Or));
 }
Ejemplo n.º 19
0
 public WhereList OR(string literalExpression)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(literalExpression);
 }
Ejemplo n.º 20
0
 public WhereList OR(string columnName, object columnValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(columnName, columnValue);
 }
Ejemplo n.º 21
0
 public WhereList OR(object thisObject, ValueObjectType thisObjectType, WhereComparison comparison, object thatObject, ValueObjectType thatObjectType)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(thisObject, thisObjectType, comparison, thatObject, thatObjectType);
 }
Ejemplo n.º 22
0
 public WhereList AND(string tableName, string columnName, object betweenValue, object andValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.AND(tableName, columnName, betweenValue, andValue);
 }
Ejemplo n.º 23
0
 public WhereList AND(IPhrase phrase, WhereComparison comparison, object value)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.AND(phrase, comparison, value);
 }
Ejemplo n.º 24
0
 public WhereList OR(WhereList whereList)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(whereList);
 }
Ejemplo n.º 25
0
 public WhereList OR(string tableName, string columnName, WhereComparison comparison, object columnValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(tableName, columnName, comparison, columnValue);
 }
Ejemplo n.º 26
0
 public WhereList OR(IPhrase phrase, WhereComparison comparison, object value, ValueObjectType valueType)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(phrase, comparison, value, valueType);
 }
Ejemplo n.º 27
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
            if (cStartDate.SelectedDate != null && cEndDate.SelectedDate != null)
            {
                WhereList w = new WhereList();
                w.Add(new Where(WhereCondition.AND, Campaign.TableSchema.SchemaName, Campaign.Columns.StartDate, WhereComparision.LessThanOrEqual, cStartDate.SelectedDate));
                w.Add(new Where(WhereCondition.AND, Campaign.TableSchema.SchemaName, Campaign.Columns.EndDate, WhereComparision.GreaterThanOrEqual, cStartDate.SelectedDate));
                if (CampaignId != 0)
                {
                    w.Add(new Where(WhereCondition.AND, Campaign.TableSchema.SchemaName, Campaign.Columns.CampaignId, WhereComparision.NotEqualsTo, CampaignId));
                }
                WhereList w1 = new WhereList();
                w1.Add(new Where(WhereCondition.AND, Campaign.TableSchema.SchemaName, Campaign.Columns.StartDate, WhereComparision.LessThanOrEqual, cEndDate.SelectedDate));
                w1.Add(new Where(WhereCondition.AND, Campaign.TableSchema.SchemaName, Campaign.Columns.EndDate, WhereComparision.GreaterThanOrEqual, cEndDate.SelectedDate));
                if (CampaignId != 0)
                {
                    w1.Add(new Where(WhereCondition.AND, Campaign.TableSchema.SchemaName, Campaign.Columns.CampaignId, WhereComparision.NotEqualsTo, CampaignId));
                }
                Query q = new Query(Campaign.TableSchema);
                q.OR(w1);
                q.OR(w);
                if (q.GetCount() > 0)
                {
                    Master.MessageCenter.DisplayErrorMessage(CampaignStrings.GetText(@"ErrorDate"));
                    return;
                }
            }
            else
            {
                Master.MessageCenter.DisplayErrorMessage(CampaignStrings.GetText(@"ErrorDate"));
                return;
            }
            Campaign campaign = Campaign.FetchByID(CampaignId);

            if (campaign == null)
            {
                campaign = new Campaign();
            }
            campaign.IsDiscount       = cbIsDiscount.Checked;
            campaign.IsGift           = cbIsGift.Checked;
            campaign.StartDate        = cStartDate.SelectedDate;
            campaign.EndDate          = cEndDate.SelectedDate;
            campaign.DestinationCount = txtDestinationCount.Text != "" ? Convert.ToInt32(txtDestinationCount.Text) : 0;
            campaign.DestinationSum   = txtDestinationSum.Text != "" ? Convert.ToInt32(txtDestinationSum.Text) : 0;
            campaign.CampaignName     = txtCampaignName.Text;
            campaign.Remarks          = txtRemarks.Text;
            campaign.PrecentDiscount  = cbIsDiscount.Checked ? (txtPrecentDiscount.Text != "" ? Convert.ToInt32(txtPrecentDiscount.Text) : 0): 0;
            campaign.ImplemationCount = txtImplemationCount.Text != "" ? Convert.ToInt32(txtImplemationCount.Text) : 0;
            campaign.Save();
            CampaignId = campaign.CampaignId;
            if (IsNewMode)
            {
                string successMessage = CampaignStrings.GetText(@"MessageCampaignCreated");
                string url            = @"EditCampaign.aspx?CampaignId=" + CampaignId;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
            }
            else
            {
                string successMessage = CampaignStrings.GetText(@"MessagCampaignUpdate");
                string url            = @"EditCampaign.aspx?CampaignId=" + CampaignId;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
            }
        }