Beispiel #1
0
        public static int UpdateUserData(string id)
        {
            DataAccessBase base2 = new DataAccessBase(connectionString);

            return(base2.NonQueryTxt(string.Format("UPDATE [dbo].[userActivity] SET [exitDate] = '{0}' WHERE id={1}", DateTime.Now, id)));
        }
Beispiel #2
0
        // Methods
        private static void createTableAndSp(string TableName, string addfieldStr, string fieldsStr, bool isExist)
        {
            string[] strArray3;
            string   str6;
            string   str14;
            string   str  = "";
            string   str2 = "";
            string   str3 = "";
            string   str4 = "";

            string[] strArray  = addfieldStr.Split(new char[] { ',' });
            string[] strArray2 = fieldsStr.Split(new char[] { ',' });
            foreach (string str5 in strArray)
            {
                if (str5.Length <= 0)
                {
                    continue;
                }
                strArray3 = str5.Split(new char[] { ':' });
                str6      = "";
                switch (strArray3[1])
                {
                case "Text":
                    str6 = "nvarchar(255)";
                    break;

                case "Number":
                    str6 = "decimal(18,2)";
                    break;

                case "Note":
                    str6 = "nvarchar(Max)";
                    break;

                case "Date":
                    str6 = "Date";
                    break;

                case "Lookup":
                    str6 = "int";
                    break;

                case "MultiLookup":
                    str6 = "nvarchar(max)";
                    break;

                case "User":
                    str6 = "int";
                    break;

                case "Choice":
                    str6 = "nvarchar(Max)";
                    break;

                case "MultiChoice":
                    str6 = "ntext";
                    break;

                case "RelatedCustomLookupQuery":
                    str6 = "int";
                    break;

                case "MasterDetail":
                    str6 = "int";
                    break;

                case "CustomComputedField":
                    str6 = "nvarchar(255)";
                    break;
                }
                str14 = str;
                str   = str14 + strArray3[0] + " " + str6 + " null,";
                str14 = str4;
                str4  = str14 + "@" + strArray3[0] + " " + str6 + ",";
                str2  = str2 + "[" + strArray3[0] + "],";
                str3  = str3 + "@" + strArray3[0] + ",";
            }
            if (str.Length > 1)
            {
                str  = str.Substring(0, str.Length - 1);
                str2 = str2.Substring(0, str2.Length - 1);
                str3 = str3.Substring(0, str3.Length - 1);
                str4 = str4.Substring(0, str4.Length - 1);
            }
            string commandText = "";
            string str8        = "";

            if (!isExist)
            {
                commandText = string.Format("create table {0} (id int not null,event nvarchar(20) not null,userId int not null,eventDate datetime not null,{1})", TableName, str);
                str8        = string.Format("CREATE PROCEDURE sp_{0}  @id int ,@event nvarchar(20),@userId int,{1} AS BEGIN \r\n                                        INSERT INTO [dbo].{0} (id,event,userid,eventDate,{2}) VALUES (@id,@event,@userid,GETDATE(),{3}) END", new object[] { TableName, str4, str2, str3 });
            }
            else
            {
                string str9  = "";
                string str10 = "";
                string str11 = "";
                string str12 = "";
                foreach (string str5 in strArray2)
                {
                    if (str5.Length <= 0)
                    {
                        continue;
                    }
                    strArray3 = str5.Split(new char[] { ':' });
                    str6      = "";
                    switch (strArray3[1])
                    {
                    case "Text":
                        str6 = "nvarchar(255)";
                        break;

                    case "Number":
                        str6 = "decimal(18,2)";
                        break;

                    case "Note":
                        str6 = "nvarchar(Max)";
                        break;

                    case "Date":
                        str6 = "Date";
                        break;

                    case "Lookup":
                        str6 = "int";
                        break;

                    case "MultiLookup":
                        str6 = "nvarchar(max)";
                        break;

                    case "User":
                        str6 = "int";
                        break;

                    case "Choice":
                        str6 = "nvarchar(Max)";
                        break;

                    case "MultiChoice":
                        str6 = "ntext";
                        break;

                    case "RelatedCustomLookupQuery":
                        str6 = "int";
                        break;

                    case "MasterDetail":
                        str6 = "int";
                        break;

                    case "CustomComputedField":
                        str6 = "nvarchar(255)";
                        break;
                    }
                    str14 = str9;
                    str9  = str14 + strArray3[0] + " " + str6 + " null,";
                    str14 = str12;
                    str12 = str14 + "@" + strArray3[0] + " " + str6 + ",";
                    str10 = str10 + "[" + strArray3[0] + "],";
                    str11 = str11 + "@" + strArray3[0] + ",";
                }
                if (str9.Length > 1)
                {
                    str9        = str9.Substring(0, str.Length - 1);
                    str12       = str12.Substring(0, str12.Length - 1);
                    str10       = str10.Substring(0, str10.Length - 1);
                    str11       = str11.Substring(0, str11.Length - 1);
                    commandText = string.Format("alter table {0}\r\n                                          add {1}\r\n                                        ", TableName, str);
                    str8        = string.Format("ALTER PROCEDURE sp_{0} @id int null,@event nvarchar(20),@userId int,{1} AS BEGIN \r\n                                        INSERT INTO [dbo].{0} (id,event,userId,eventDate,{2}) VALUES (@id,@event,@userId,GETDATE(),{3}) END", new object[] { TableName, str12, str10, str11 });
                }
            }
            DataAccessBase base2 = new DataAccessBase(connectionString);

            base2.NonQueryTxt(commandText);
            base2.NonQueryTxt(str8);
        }