Exemplo n.º 1
0
        /// <summary>
        /// Get all object prepare to send to server
        /// </summary>
        /// <param name="KeyColumn"></param>
        /// <returns></returns>
        public static List <T> GetAllToSend(string KeyColumn)
        {
            string   tableName = WebCore.GetTableName(typeof(T));
            string   SQL       = "SELECT * FROM [" + tableName + "] WHERE " + KeyColumn + " NOT IN (SELECT " + KeyColumn + " FROM [Syn" + tableName + "])";
            List <T> result    = null;
            DataSet  dataset   = SqlHelper.ExecuteDataset(Config.ConnectionString, CommandType.Text, SQL);

            if (dataset != null && dataset.Tables.Count > 0)
            {
                DataTable table = dataset.Tables[0];
                result = new List <T>();
                foreach (DataRow row in table.Rows)
                {
                    T obj = GetObject(row);
                    result.Add(obj);
                }
                table.Dispose();
            }
            dataset.Dispose();
            return(result);
        }
Exemplo n.º 2
0
        public static bool SaveLog(List <T> list)
        {
            string tableName = WebCore.GetTableName(typeof(T));

            PropertyInfo[] infos     = (typeof(T)).GetProperties();
            string         KeyColumn = string.Empty;
            int            KeyIndex  = -1;

            foreach (PropertyInfo info in infos)
            {
                KeyIndex++;
                if (info.PropertyType.Name == "ExtensionDataObject")
                {
                    continue;
                }
                KeyColumn = info.Name;
                break;
            }
            //-----------------------------------------------------------------------------------------------------
            //--------------------------------SAVE TO MAPPING TABLE------------------------------------------------
            try
            {
                foreach (T obj in list)
                {
                    //Add to log table
                    string         SQL2     = "INSERT INTO [Syn" + tableName + "] VALUES (@" + KeyColumn + ")";
                    SqlParameter[] parames2 = new SqlParameter[] { new SqlParameter("@" + KeyColumn, infos[KeyIndex].GetValue(obj, null)) };
                    int            j        = SqlHelper.ExecuteNonQuery(Config.ConnectionString, CommandType.Text, SQL2, parames2);
                }
                //if (j == -1) return false;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send an object to server
        /// </summary>
        /// <param name="ClientID"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool SendToSV(string ClientID, T obj)
        {
            string KeyColumn = string.Empty;
            object KeyValue  = null;

            //Another parameter in table which is referenced
            string tableName = WebCore.GetTableName(typeof(T));

            PropertyInfo[] infos = (typeof(T)).GetProperties();
            try
            {
                //Parameter root - ClientID
                List <SqlParameter> parames = new List <SqlParameter>();
                SqlParameter        param0  = new SqlParameter("@ClientID", ClientID);
                parames.Add(param0);

                string SQL      = "INSERT INTO [" + tableName + "] VALUES (@ClientID";
                int    KeyIndex = -1;
                foreach (PropertyInfo info in infos)
                {
                    KeyIndex++;
                    //remove uneccessary column
                    if (info.PropertyType.Name == "ExtensionDataObject")
                    {
                        continue;
                    }
                    if (info.PropertyType != typeof(string) &&
                        info.PropertyType.GetInterface(typeof(IEnumerable).Name) != null &&
                        info.PropertyType.GetInterface(typeof(IEnumerable <>).Name) != null)
                    {
                        continue;
                    }


                    object valueP = info.GetValue(obj, null);
                    if (KeyColumn == string.Empty)
                    {
                        KeyColumn = info.Name;
                    }
                    if (KeyValue == null)
                    {
                        KeyValue = valueP;
                    }
                    if (valueP is DateTime && (DateTime)valueP == DateTime.MinValue)
                    {
                        valueP = DBNull.Value;
                    }
                    SqlParameter param = new SqlParameter("@" + info.Name, valueP ?? DBNull.Value);
                    parames.Add(param);

                    SQL += ", @" + info.Name;
                }
                SQL += ")";

                //--------------------------------DELETE IF EXIST FROM SERVER TABLE-----------------------------------
                string       sqlDelete      = "DELETE FROM [" + tableName + "] WHERE ClientID=@ClientID AND " + KeyColumn + "=@" + KeyColumn;
                SqlParameter paramClientID  = new SqlParameter("@ClientID", ClientID);
                SqlParameter paramKeyColumn = new SqlParameter("@" + KeyColumn, KeyValue ?? DBNull.Value);
                SqlHelper.ExecuteNonQuery(Config.SVConnectionString, CommandType.Text, sqlDelete, new SqlParameter[] { paramClientID, paramKeyColumn });

                //--------------------------------SAVE TO SERVER TABLE------------------------------------------------
                int i = SqlHelper.ExecuteNonQuery(Config.SVConnectionString, CommandType.Text, SQL, parames.ToArray());
                if (i == -1)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }