static void Main(string[] args) { Console.WriteLine("Press any key to drop Database"); Console.Read(); System.Data.Entity.Database.SetInitializer<Context>(new ContextDropDBInitializer()); //System.Data.Entity.Database.SetInitializer<Context>(null); Context db = new Context(); var query = (from o in db.SystemUsers select o).ToList(); db.Dispose(); ImportData import = new ImportData(); string filename = "历史客户.xlsx"; //import.Fun1(filename); Console.WriteLine("Press any key to Exit"); Console.Read(); }
public void Fun() { string filename = "人员名单.xlsx"; FileInfo fi = new FileInfo(filename); StringBuilder errorinfo = new StringBuilder(); using (ExcelPackage package = new ExcelPackage(fi)) { ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"]; int i = 1; using (Context db = new Context()) { //db.Configuration.AutoDetectChangesEnabled = false; //using (TransactionScope tran = new TransactionScope()) //{ while (i < 100) { i++; string name = ExcelHelper.ReadString(worksheet.Cells[i, 4]); if (string.IsNullOrEmpty(name)) continue; if ((from o in db.SystemUsers where o.Name == name select o).FirstOrDefault() != null) { Console.WriteLine(name + " 已存在"); continue; } string rolename = ExcelHelper.ReadString(worksheet.Cells[i, 2]); int roleid = (from o in db.Roles where o.Name == rolename select o.Id).FirstOrDefault(); if (roleid == 0) { roleid= (from o in db.Roles where o.Name == "销售员" select o.Id).First(); } SystemUser user = new SystemUser { Name = name, Password = "******", LoginName = name, Email = ExcelHelper.ReadString(worksheet.Cells[i, 5]) }; SystemUser u = new SystemUser(); db.SystemUsers.Add(u); u.Save(db, user); RoleUser ru = new RoleUser {UserId = u.Id, RoleId = (int) roleid}; db.RoleUsers.Add(ru); string projname = ExcelHelper.ReadString(worksheet.Cells[i, 1]); int project = (from o in db.Departments where o.Name == projname select o.Id).First(); DepartmentUser du = new DepartmentUser {UserId = u.Id}; string d3 = ExcelHelper.ReadString(worksheet.Cells[i, 3]); if (string.IsNullOrEmpty(d3)) { d3 = "公共客户"; } else { d3 = rolename; } Department dept = (from o in db.Departments where o.PId == project && o.Name == d3 select o).First(); du.DepartmentId = dept.Id; db.DepartmentUsers.Add(du); db.SaveChanges(); // tran.Complete(); // } } } } }
public void Fun1(string filename) { FileInfo fi = new FileInfo(filename); StringBuilder errorinfo = new StringBuilder(); using (ExcelPackage package = new ExcelPackage(fi)) { ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"]; int i = 1; using (Context db = new Context()) { //db.Configuration.AutoDetectChangesEnabled = false; //using (TransactionScope tran = new TransactionScope()) //{ while (i < 6000) { i++; string name = ExcelHelper.ReadString(worksheet.Cells[i, 3]); if (string.IsNullOrEmpty(name)) continue; int projectid = int.Parse(ExcelHelper.ReadString(worksheet.Cells[i, 9])); DateTime? d = ExcelHelper.ReadDateEmpty(worksheet.Cells[i, 2]); if (d == null) { Console.WriteLine("ErrorDate" + i.ToString()); continue; } string phone = ExcelHelper.ReadString(worksheet.Cells[i, 4]); string way = ExcelHelper.ReadString(worksheet.Cells[i, 5]); if (string.IsNullOrEmpty(way)) { way = "-"; } string roomtype = ExcelHelper.ReadString(worksheet.Cells[i, 6]); //string u1 = ExcelHelper.ReadString(worksheet.Cells[i, 7]); string u2 = ExcelHelper.ReadString(worksheet.Cells[i, 8]); if (phone != "-") { if ( (from o in db.Clients where o.ProjectId == projectid && o.Phone1 == phone select o) .FirstOrDefault() !=null) { Console.WriteLine("客户已存在" + i.ToString()); continue; } } int sales1 = (from o in db.SystemUsers where o.Name == u2 select o.Id).FirstOrDefault(); int sales; if (sales1 == 0) { Console.WriteLine("销售员不存在" + u2+i.ToString()); continue; } sales = (int) sales1; int team1 = (from o in db.SystemUsers join p in db.DepartmentUsers on o.Id equals p.UserId where o.Name == u2 select p.DepartmentId).FirstOrDefault(); if (team1 == 0) { Console.WriteLine("销售组不存在" + u2); continue; } int team=(int)team1; Client client = new Client {ProjectId = projectid}; client.Name = name; client.Phone1 = phone; client.Way = way; client.RoomType = roomtype; client.AllPhone = phone; client.Code = "导入数据"; client.CreateTime = (DateTime)d; client.GroupId = team; client.State = ClientStateEnum.来电客户; client.StateDate = new DateTime(2013, 11, 30); db.Clients.Add(client); db.SaveChanges(); ClientActivity ca = new ClientActivity {ClientId = client.Id}; db.ClientActivities.Add(ca); ca.ActualTime = client.CreateTime; ca.FirstType = 1; ca.Person = sales; ca.Type = "来电"; db.SaveChanges(); } //tran.Complete(); // } } } }
static void Main (string[] args) { Platform[] platforms = Platform.GetPlatforms (); for (int i = 0; i < platforms.Length; i++) { Console.WriteLine ("Platform={0}", i); Console.WriteLine (" Name = {0}", platforms[i].Name); Console.WriteLine (" Vendor = {0}", platforms[i].Vendor); Console.WriteLine (" Version = {0}", platforms[i].Version); Console.WriteLine (" Profile = {0}", platforms[i].Profile); Console.WriteLine (" Extensions = {0}", platforms[i].Extensions); Device[] devices = platforms[0].GetDevices (DeviceType.All); for (int j = 0; j < devices.Length; j++) { Console.WriteLine (" Device={0}", j); Console.WriteLine (" Name = {0}", devices[j].Name); Console.WriteLine (" Vendor = {0}", devices[j].Vendor); Console.WriteLine (" MaxComputeUnits = {0}", devices[j].MaxComputeUnits); } } int blockSize = 16; int matrixSize = 1024; int matrixBytes = matrixSize * matrixSize * 4; float[] matrixA = new float[matrixSize * matrixSize]; float[] matrixB = new float[matrixSize * matrixSize]; float[] matrixR = new float[matrixSize * matrixSize]; float[] matrixCPU = new float[matrixSize * matrixSize]; int[] global_threads = new int[] {matrixSize, matrixSize}; int[] local_threads = new int[] {blockSize, blockSize}; int blockCacheBytes = blockSize * blockSize * 4; Random rnd = new Random (); for (int i = 0; i < matrixA.Length; i ++) { matrixA[i] = (float)rnd.NextDouble (); matrixB[i] = (float)rnd.NextDouble (); } Stopwatch sw; Device device; using (Context context = new Context (DeviceType.GPU)) using (CommandQueue queue = context.CreateCommandQueue (device = context.Devices[0], CommandQueueProperties.Default)) using (Memory memA = context.CreateBuffer (MemoryFlags.ReadOnly, matrixBytes)) using (Memory memB = context.CreateBuffer (MemoryFlags.ReadOnly, matrixBytes)) using (Memory memC = context.CreateBuffer (MemoryFlags.WriteOnly, matrixBytes)) using (Program prog = context.CreateProgram (OpenCL_TestProgram, device, null)) using (Kernel kernel = prog.CreateKernel ("multMatrix")) { kernel.SetArgument (0, memA); kernel.SetArgument (1, memB); kernel.SetArgument (2, memC); kernel.SetLocalDataShare (3, blockCacheBytes); kernel.SetLocalDataShare (4, blockCacheBytes); kernel.SetArgument (5, matrixSize, 4); kernel.SetArgument (6, blockSize, 4); queue.WriteBuffer (memA, 0, matrixA, 0, matrixBytes); queue.WriteBuffer (memB, 0, matrixB, 0, matrixBytes); sw = Stopwatch.StartNew (); queue.Execute (kernel, null, global_threads, local_threads); sw.Stop (); Console.WriteLine ("GPU: {0:f4}ms", sw.Elapsed.TotalMilliseconds); queue.ReadBuffer (memC, 0, matrixR, 0, matrixBytes); } sw = Stopwatch.StartNew (); for (int i = 0; i < matrixSize; i ++) { for (int j = 0; j < matrixSize; j ++) { for (int k = 0; k < matrixSize; k ++) matrixCPU[i * matrixSize + j] += matrixA[i * matrixSize + k] * matrixB[k * matrixSize + j]; } } sw.Stop (); Console.WriteLine ("CPU: {0:f4}ms", sw.Elapsed.TotalMilliseconds); for (int i = 0; i < matrixR.Length; i ++) { if (matrixR[i] != matrixCPU[i]) { Console.WriteLine ("Error"); return; } } Console.WriteLine ("OK"); }