/// <summary> /// add value without columnsname /// </summary> /// <param name="Value">cloumn value</param> /// <returns></returns> public void AddInsertColumn(object[] Value) { if (Value.Length == 0) { throw new Exception("Values is null."); } if (valuename.Equals("NULL")) { throw new Exception("Already set InsertType.InsertSelect Mode."); } for (int i = 0; i < Value.Length; i++) { if (valuename.Length > 0) { valuename += ","; } if (CommonService.CheckValueType(Value[i]) && Value[i].ToString().Contains("(") == false && Value[i].ToString().Contains(")") == false) { Value[i] = String.Format("'{0}'", Value[i]); } valuename += Value[i]; } }
/// <summary> /// add where condition with list /// </summary> /// <param name="Relation"></param> /// <param name="ColumnName"></param> /// <param name="Comparison"></param> /// <param name="Value"></param> public void AddWhere(WhereRelation Relation, String ColumnName, CommandComparison Comparison, object[] Value) { String Condition; if (String.IsNullOrEmpty(ColumnName)) { throw new Exception("Values is null."); } if (!(Comparison == CommandComparison.In || Comparison == CommandComparison.NotIn)) { throw new Exception("only support In comparison."); } Condition = "("; foreach (object value in Value) { if (CommonService.CheckValueType(value)) { Condition = Condition + "'" + value + "',"; } else { Condition = Condition + value + ","; } } Condition += ")"; Condition = Condition.Replace(",)", ")"); condition.Add(String.Format(" {0} {1} {2} {3}", CommonService.GetWhereRelation(Relation), ColumnName, CommonService.ConvertComparison(Comparison), Condition)); }
/// <summary> /// add columns name and values name /// </summary> /// <param name="ColumnName">cloumn name</param> /// <param name="Value">cloumn value</param> /// <returns></returns> public void AddInsertColumn(String[] ColumnName, object[] Value) { if (ColumnName.Length == 0) { throw new Exception("Cloumn name is null."); } if (ColumnName.Length != Value.Length) { throw new Exception("Cloumns number not equal values number."); } if (valuename.Equals("NULL")) { throw new Exception("Already set InsertType.InsertSelect Mode."); } if (fieldname.Equals("NULL")) { throw new Exception("Already set DefaultCloumnName Mode."); } foreach (String column in ColumnName) { if (fieldname.Length > 0) { fieldname += ","; } fieldname += column; } for (int i = 0; i < Value.Length; i++) { if (valuename.Length > 0) { valuename += ","; } if (CommonService.CheckValueType(Value[i]) && Value[i].ToString().Contains("(") == false && Value[i].ToString().Contains(")") == false) { Value[i] = String.Format("'{0}'", Value[i]); } valuename += Value[i]; } }
/// <summary> /// add where condition /// </summary> /// <param name="Relation"></param> /// <param name="ColumnName"></param> /// <param name="Comparison"></param> /// <param name="value"></param> public void AddWhere(WhereRelation Relation, String ColumnName, CommandComparison Comparison, object value) { if (String.IsNullOrEmpty(ColumnName)) { throw new Exception("Values is null."); } if (CommonService.CheckValueType(value)) { condition.Add(String.Format(" {0} {1} {2} {3}", CommonService.GetWhereRelation(Relation), ColumnName, CommonService.ConvertComparison(Comparison), "'" + value + "'")); } else { condition.Add(String.Format(" {0} {1} {2} {3}", CommonService.GetWhereRelation(Relation), ColumnName, CommonService.ConvertComparison(Comparison), value)); } }
/// <summary> /// add Having condition /// </summary> /// <param name="ColumnName"></param> /// <param name="Comparison"></param> /// <param name="value"></param> public void AddHaving(String ColumnName, CommandComparison Comparison, object value1, object value2) { String Condition; if (String.IsNullOrEmpty(ColumnName)) { throw new Exception("Values is null."); } if (groupcondition.Count == 0) { throw new Exception("Need set group by condition first."); } if (!(Comparison == CommandComparison.Between || Comparison == CommandComparison.NotBetween)) { throw new Exception("only support Between comparison."); } if (CommonService.CheckValueType(value1)) { Condition = String.Format("{0} {1} {2}", ColumnName, CommonService.ConvertComparison(Comparison), "'" + value1 + "'"); } else { Condition = String.Format("{0} {1} {2}", ColumnName, CommonService.ConvertComparison(Comparison), value1); } if (CommonService.CheckValueType(value2)) { Condition += "and '" + value2 + "'"; } else { Condition += "and " + value2; } havingcondition.Add(Condition); }
/// <summary> /// add Having condition /// </summary> /// <param name="ColumnName"></param> /// <param name="Comparison"></param> /// <param name="value"></param> public void AddHaving(String ColumnName, CommandComparison Comparison, object value) { if (String.IsNullOrEmpty(ColumnName)) { throw new Exception("Values is null."); } if (groupcondition.Count == 0) { throw new Exception("Need set group by condition first."); } if (CommonService.CheckValueType(value)) { havingcondition.Add(String.Format("{0} {1} {2}", ColumnName, CommonService.ConvertComparison(Comparison), "'" + value + "'")); } else { havingcondition.Add(String.Format("{0} {1} {2}", ColumnName, CommonService.ConvertComparison(Comparison), value)); } }
/// <summary> /// add Having condition /// </summary> /// <param name="ColumnName"></param> /// <param name="Comparison"></param> /// <param name="value"></param> public void AddHaving(String ColumnName, CommandComparison Comparison, object[] Value) { String Condition; if (String.IsNullOrEmpty(ColumnName)) { throw new Exception("Values is null."); } if (groupcondition.Count == 0) { throw new Exception("Need set group by condition first."); } if (!(Comparison == CommandComparison.In || Comparison == CommandComparison.NotIn)) { throw new Exception("only support In comparison."); } Condition = "("; foreach (object value in Value) { if (CommonService.CheckValueType(value)) { Condition = Condition + "'" + value + "',"; } else { Condition = Condition + value + ","; } } Condition += ")"; Condition = Condition.Replace(",)", ")"); havingcondition.Add(String.Format("{0} {1} {2}", ColumnName, CommonService.ConvertComparison(Comparison), Condition)); }
/// <summary> /// add where condition with between /// </summary> /// <param name="Relation"></param> /// <param name="ColumnName"></param> /// <param name="Comparison"></param> /// <param name="value1"></param> /// <param name="value2"></param> public void AddWhere(WhereRelation Relation, String ColumnName, CommandComparison Comparison, object value1, object value2) { String Condition; if (String.IsNullOrEmpty(ColumnName)) { throw new Exception("Values is null."); } if (!(Comparison == CommandComparison.Between || Comparison == CommandComparison.NotBetween)) { throw new Exception("only support Between comparison."); } if (CommonService.CheckValueType(value1)) { Condition = String.Format(" {0} {1} {2} {3}", CommonService.GetWhereRelation(Relation), ColumnName, CommonService.ConvertComparison(Comparison), "'" + value1 + "'"); } else { Condition = String.Format(" {0} {1} {2} {3}", CommonService.GetWhereRelation(Relation), ColumnName, CommonService.ConvertComparison(Comparison), value1); } if (CommonService.CheckValueType(value2)) { Condition += " and '" + value2 + "'"; } else { Condition += " and " + value2; } condition.Add(Condition); }