using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; using System.Data; using System.Configuration; using System.Runtime.Serialization.Json; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Web.Services.Protocols; using System.Security.Cryptography; using System.Text; using System.Web.SessionState; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runtime.Serialization; /// /// project 的摘要描述 /// public class project : projectBase { public List project_users; public List projectApi_domains; public List projectApi_ips; public userdata project_createUser; [IgnoreDataMember] public string update_result = ""; autoBindDataTable projectSQL; autoExecSQL recExec; string recString = ""; Boolean isNew = false; DataRow projectRow; public project() : base() { // // TODO: 在這裡新增建構函式邏輯 // project_users = new List(); projectApi_domains = new List(); projectApi_ips = new List(); string projectString = "select * from projects where project_sn = -1"; projectSQL = new autoBindDataTable(projectString); projectRow = projectSQL.newRow; projectSQL.dataRows.Add(projectRow); isNew = true; authPermission objAuth = new authPermission(); project_createUid = objAuth.user_uid; } public project(string project_uid) : base(project_uid) { projectSQL = projectBaseSQL; projectRow = projectBaseRow; project_users = new List(); projectApi_domains = new List(); projectApi_ips = new List(); project_createUser = new userdata(project_createUid); string apiDomainString = string.Format("select * from projectApiDomain where project_uid = '{0}'", project_uid); autoBindDataTable sqlApiDomain = new autoBindDataTable(apiDomainString); foreach (DataRow tmpRow in sqlApiDomain.dataRows) { projectApiDomainBase tmpApi = new projectApiDomainBase(); tmpApi.project_uid = project_uid; tmpApi.projectApiDomain_type = tmpRow["projectApiDomain_type"].ToString(); tmpApi.projectApiDomain_address = tmpRow["projectApiDomain_address"].ToString(); if (tmpApi.projectApiDomain_type == "domain") { projectApi_domains.Add(tmpApi); } if (tmpApi.projectApiDomain_type == "ip") { projectApi_ips.Add(tmpApi); } } string userString = string.Format("select * from projectUser where project_uid = '{0}' and user_uid <> ''", project_uid); autoBindDataTable sqlUser = new autoBindDataTable(userString); foreach (DataRow tmpRow in sqlUser.dataRows) { userdata tmpUser = new userdata(tmpRow["user_uid"].ToString()); project_users.Add(tmpUser); } } public Boolean updateData() { Boolean result = false; update_result = "更新失敗!"; authPermission objAuth = new authPermission(); if (objAuth.isLogin() == false) { update_result = "無權限!"; return result; } projectRow["project_uid"] = project_uid; projectRow["project_name"] = project_name; projectRow["project_descript"] = project_descript; projectRow["project_recTableName"] = project_recTableName; projectRow["project_dateLimit"] = project_dateLimit; projectRow["project_endDate"] = project_endDate; projectRow["project_endToRedirect"] = project_endToRedirect; projectRow["project_apiId"] = project_apiId; projectRow["project_apiKey"] = project_apiKey; projectRow["project_createUid"] = project_createUid; if (isNew) { recString += string.Format(" CREATE TABLE [dbo].[rec_{0}](", project_uid); recString += string.Format(" [rec_sn] [int] IDENTITY(1,1) NOT NULL,"); recString += string.Format(" [project_uid] [nvarchar](36) NOT NULL,"); recString += string.Format(" [url_uid] [nvarchar](36) NOT NULL,"); recString += string.Format(" [rec_sourceIP] [nvarchar](36) NOT NULL,"); recString += string.Format(" [rec_sourceDomain] [nvarchar](500) NOT NULL,"); recString += string.Format(" [rec_country] [nvarchar](50) NOT NULL,"); recString += string.Format(" [rec_city] [nvarchar](50) NOT NULL,"); recString += string.Format(" [rec_loc] [nvarchar](50) NOT NULL,"); recString += string.Format(" [rec_createdate] [datetime] NOT NULL,"); recString += string.Format(" CONSTRAINT [PK_rec_{0}] PRIMARY KEY CLUSTERED ", project_uid); recString += string.Format("("); recString += string.Format(" [rec_sn] ASC"); recString += string.Format(") WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]"); recString += string.Format(") ON [PRIMARY];"); recString += string.Format(" CREATE NONCLUSTERED INDEX [IX_rec_{0}] ON [dbo].[rec_{1}]", project_uid, project_uid); recString += string.Format(" ("); recString += string.Format(" [project_uid] ASC"); recString += string.Format(")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY];"); recString += string.Format(" CREATE NONCLUSTERED INDEX [IX_rec_{0}_1] ON [dbo].[rec_{1}]", project_uid, project_uid); recString += string.Format(" ("); recString += string.Format(" [url_uid] ASC"); recString += string.Format(")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY];"); recString += string.Format(" CREATE NONCLUSTERED INDEX [IX_rec_{0}_2] ON [dbo].[rec_{1}]", project_uid, project_uid); recString += string.Format("("); recString += string.Format(" [project_uid] ASC,"); recString += string.Format(" [url_uid] ASC"); recString += string.Format(") WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY];"); recString += string.Format(" CREATE NONCLUSTERED INDEX [IX_rec_{0}_3] ON [dbo].[rec_{1}]", project_uid, project_uid); recString += string.Format(" ("); recString += string.Format(" [rec_createdate] ASC"); recString += string.Format(") WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY];"); recString += string.Format(" CREATE NONCLUSTERED INDEX [IX_rec_{0}_4] ON [dbo].[rec_{1}]", project_uid, project_uid); recString += string.Format("("); recString += string.Format(" [url_uid] ASC,"); recString += string.Format(" [rec_createdate] ASC"); recString += string.Format(")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY];"); recString += string.Format(" CREATE NONCLUSTERED INDEX [IX_rec_{0}_5] ON [dbo].[rec_{1}]", project_uid, project_uid); recString += string.Format("("); recString += string.Format(" [project_uid] ASC,"); recString += string.Format(" [url_uid] ASC,"); recString += string.Format(" [rec_createdate] ASC"); recString += string.Format(") WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY];"); recString += string.Format(" ALTER TABLE [dbo].[rec_{0}] ADD CONSTRAINT [DF_rec_{1}_project_uid] DEFAULT ('') FOR [project_uid];", project_uid, project_uid); recString += string.Format(" ALTER TABLE [dbo].[rec_{0}] ADD CONSTRAINT [DF_rec_{1}_url_uid] DEFAULT ('') FOR [url_uid];", project_uid, project_uid); recString += string.Format(" ALTER TABLE [dbo].[rec_{0}] ADD CONSTRAINT [DF_rec_{1}_rec_sourceIP] DEFAULT ('') FOR [rec_sourceIP];", project_uid, project_uid); recString += string.Format(" ALTER TABLE [dbo].[rec_{0}] ADD CONSTRAINT [DF_rec_{1}_rec_sourceDomain] DEFAULT ('') FOR [rec_sourceDomain];", project_uid, project_uid); recString += string.Format(" ALTER TABLE [dbo].[rec_{0}] ADD CONSTRAINT [DF_rec_{1}_rec_country] DEFAULT ('') FOR [rec_country];", project_uid, project_uid); recString += string.Format(" ALTER TABLE [dbo].[rec_{0}] ADD CONSTRAINT [DF_rec_{1}_rec_city] DEFAULT ('') FOR [rec_city]", project_uid, project_uid); recString += string.Format(" ALTER TABLE [dbo].[rec_{0}] ADD CONSTRAINT [DF_rec_{1}_rec_createdate] DEFAULT (getdate()) FOR [rec_createdate];", project_uid, project_uid); } try { projectSQL.updateDataTable(); if (isNew) { autoExecSQL objNewRec = new autoExecSQL(recString); } result = true; update_result = ""; } catch (Exception ex) { result = false; update_result = ex.Message; } return result; } }