Exemple #1
0
        public string deleteDate(SQLParameter Parameter)
        {
            StringBuilder SQLString = new StringBuilder();

            SQLString.Append(@"Delete " + TBName + " Where 1=1");
            foreach (var pa in Parameter.WhereCondition)
            {
                SQLString.Append(string.Concat(" And " + pa.Key + " =" + pa.Value));
            }
            bool Result = ExcuteAction(Conn, SQLString.ToString());

            if (Result)
            {
                return("刪除成功!");
            }
            else
            {
                return("刪除失敗!");
            }
        }
Exemple #2
0
        public string editData(SQLParameter Parameter)
        {
            StringBuilder SQLString = new StringBuilder();

            SQLString.Append(string.Concat("Update " + TBName));
            SQLString.Append(" Set ");
            string ConnetSetValue = string.Empty;

            foreach (var pa in Parameter.SetActionValue)
            {
                if (!string.IsNullOrEmpty(ConnetSetValue))
                {
                    ConnetSetValue += ",";
                }
                ConnetSetValue += string.Concat(pa.Key + " = " + "@" + pa.Key);
            }
            SQLString.Append(string.Concat(ConnetSetValue));
            ExcuteAction(Conn, SQLString.ToString(), Parameter);
            return(null);
        }
Exemple #3
0
        public string addData(SQLParameter Parameter)
        {
            StringBuilder SQLString = new StringBuilder();

            SQLString.Append(string.Concat("INSERT INTO " + TBName));
            SQLString.Append(" VALUES( ");
            string ConnetSetValue = string.Empty;

            foreach (var pa in Parameter.SetActionValue)
            {
                if (!string.IsNullOrEmpty(ConnetSetValue))
                {
                    ConnetSetValue += ",";
                }
                ConnetSetValue += string.Concat("@" + pa.Key);
            }
            SQLString.Append(string.Concat(ConnetSetValue + " )"));
            ExcuteAction(Conn, SQLString.ToString(), Parameter);
            return(null);
        }
Exemple #4
0
 protected bool ExcuteAction(SqlConnection Conn, string SQLString, SQLParameter Parameter = null)
 {
     using (SqlConnection myConn = Conn)
     {
         myConn.Open();
         SqlTransaction tran = myConn.BeginTransaction();
         try
         {
             int result = 0;
             using (SqlCommand cmd = new SqlCommand(SQLString, myConn, tran))
             {
                 if (Parameter != null && Parameter.SetActionValue.Count > 0)
                 {
                     foreach (var pa in Parameter.SetActionValue)
                     {
                         cmd.Parameters.AddWithValue(pa.Key, pa.Value);
                     }
                 }
                 result = cmd.ExecuteNonQuery();
             }
             tran.Commit();//無錯誤 commit
             if (result > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception ex)
         {
             tran.Rollback();//錯誤 rollback
             return(false);
         }
         finally
         {
             Conn.Close();
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// 查詢Tabel TB_Calendar
        /// </summary>
        /// <param name="Parameter"></param>
        /// <returns></returns>
        public DataTable getData(SQLParameter Parameter = null)
        {
            string SqlString = combinationQuerySQLString(Parameter, TBName);

            return(QueryExcute(Conn, SqlString.ToString()));
        }
 public string editData(SQLParameter Parameter)
 {
     throw new NotImplementedException();
 }