public TencentUser GetTencentUser(string openid, string devmodel, string version) { if (version == null || version == "") { version = "1"; } TencentUser tu = ve.TencentUser.FirstOrDefault(q => q.OpenId == openid && q.Version == version); if (tu == null) { tu = ve.TencentUser.FirstOrDefault(q => (q.OpenId == null || q.OpenId == "") && q.Version == version); if (tu != null) { tu.OpenId = openid; tu.DevModel = devmodel; tu.ActivateDate = DateTime.Now; tu.Version = version; ve.SaveChanges(); } } return(tu); }
private void button2_Click(object sender, EventArgs e) { List <TencentUser> tencentUserlist = new List <TencentUser>(); foreach (DataGridViewRow item in this.dataGridView1.Rows) { string _GUID = item.Cells["GUID"].Value + ""; string _License = item.Cells["License"].Value + ""; string GUID = item.Cells["GUID"].Value + ""; string _Version = version.Text; TencentUser tencentUser = new TencentUser() { OpenId = "", GUID = _GUID, License = _License, CreateDate = DateTime.Now, Version = _Version }; if (guidlist.Contains(tencentUser.GUID)) { tencentUserlist.Add(tencentUser); continue; } if (item.Cells["State"].Value.ToString() == "OK") { continue; } } if (tencentUserlist.Count != 0) { if (MessageBox.Show("数据库重复有" + tencentUserlist.Count + "条,是否继续录入没有重复的", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { foreach (DataGridViewRow item in this.dataGridView1.Rows) { string _GUID = item.Cells["GUID"].Value + ""; string _License = item.Cells["License"].Value + ""; string GUID = item.Cells["GUID"].Value + ""; string _Version = version.Text; TencentUser tencentUser = new TencentUser() { OpenId = "", GUID = _GUID, License = _License, CreateDate = DateTime.Now, Version = _Version }; if (guidlist.Contains(tencentUser.GUID)) { continue; } if (item.Cells["State"].Value.ToString() == "OK") { continue; } // 执行 ve.TencentUser.Add(tencentUser); int num = ve.SaveChanges(); if (num > 0) { item.Cells["State"].Value = "OK"; } else { item.Cells["State"].Value = "NO"; } } } } else { foreach (DataGridViewRow item in this.dataGridView1.Rows) { string _GUID = item.Cells["GUID"].Value + ""; string _License = item.Cells["License"].Value + ""; string GUID = item.Cells["GUID"].Value + ""; string _Version = version.Text; TencentUser tencentUser = new TencentUser() { OpenId = "", GUID = _GUID, License = _License, CreateDate = DateTime.Now, Version = _Version }; if (guidlist.Contains(tencentUser.GUID)) { continue; } if (item.Cells["State"].Value.ToString() == "OK") { continue; } // 执行 ve.TencentUser.Add(tencentUser); int num = ve.SaveChanges(); if (num > 0) { item.Cells["State"].Value = "OK"; } else { item.Cells["State"].Value = "NO"; } } } }