private void BtnOK_Click(object sender, EventArgs e) { using (var db = new ICMServer.Models.ICMDBContext()) { holderinfo ResidentIndfo = new holderinfo(); ResidentIndfo.C_name = textBoxName.Text; ResidentIndfo.C_roomid = textBoxRoomID.Text; ResidentIndfo.C_sex = ComboBoxSex.SelectedIndex; ResidentIndfo.C_isholder = ComboBoxIsResident.SelectedIndex; ResidentIndfo.C_phoneno = textBoxPhone.Text; //ResidentIndfo.birth = dateTimePickerBirth.Value; //ResidentIndfo.PID = textBoxPID.Text; db.Holderinfoes.Add(ResidentIndfo); db.SaveChanges(); } this.Close(); }
public static void AddDevices(AddrList addrList, IProgress <int> progress = null) { Stopwatch stopwatch = Stopwatch.StartNew(); using (var db = new ICMDBContext()) { db.Database.ExecuteSqlCommand("DELETE FROM Device"); db.Database.ExecuteSqlCommand("ALTER TABLE Device AUTO_INCREMENT = 1"); int processCount = 0; int reportedProgressPercentage = -1; foreach (var d in addrList.dev) { Device dev = new Device { ip = d.ip, roomid = d.ro, Alias = (d.IsaliasNull()) ? null : d.alias, group = (d.IsgroupNull()) ? null : d.group, mac = (d.IsmcNull()) ? null : d.mc, type = d.ty, sm = d.sm, gw = d.gw, cameraid = (d.IsidNull()) ? null : d.id, camerapw = (d.IspwNull()) ? null : d.pw }; db.Devices.Add(dev); processCount++; if (progress != null) { int currentProgressPercentage = (processCount * 99 / addrList.dev.Count); if (reportedProgressPercentage != currentProgressPercentage) { reportedProgressPercentage = currentProgressPercentage; progress.Report(reportedProgressPercentage); } } } db.SaveChanges(); if (progress != null) { progress.Report(100); } } stopwatch.Stop(); //DebugLog.TraceMessage(string.Format("done: {0}", stopwatch.Elapsed)); }