private void btnDelete_Click(object sender, EventArgs e) { if (this.dgAgentWechatAccount.CurrentRow==null) { MessageBox.Show("请选择一行记录"); return; } String userId= this.dgAgentWechatAccount.CurrentRow.Cells[6].Value.ToString(); if (!String.IsNullOrEmpty(userId)) { WechatAction wechatAction = new Wechat.WechatAction(); HttpResult result = wechatAction.deleteUserFromWechat(userId, Settings.Default.Wechat_Secret); if (result.StatusCode == System.Net.HttpStatusCode.OK) { AgentWechatAccountDao agentWechatAccountDao = new AgentWechatAccountDao(); agentWechatAccountDao.Delete(userId); this.prepareGrid(this.txtKeyword.Text.Trim(), this.cboType.Text.Trim(),this.checkUnsync.Checked); } } }
private void saveGridData(DataGridView dg, String type) { ArrayList AgentNoList = new ArrayList(); ArrayList WechatNoList = new ArrayList(); for (int i = 0; i < dgAgentWechatAccount.RowCount; i++) { AgentNoList.Add(dgAgentWechatAccount[4, i].Value.ToString()); if (!String.IsNullOrEmpty(dgAgentWechatAccount[7, i].Value.ToString())) { WechatNoList.Add(dgAgentWechatAccount[7, i].Value.ToString()); } } AgentWechatAccountDao agentWechatAccountDao = new AgentWechatAccountDao(); for (int i = 0; i < dg.RowCount; i++) { AgentWechatAccount agentWechatAccount = new AgentWechatAccount(); int index = 0; agentWechatAccount.type = type; if (dg.Columns[0].HeaderText.Equals("区县")) { agentWechatAccount.regionName = dg[index++, i].Value.ToString(); agentWechatAccount.branchNo = dg[index++, i].Value.ToString(); agentWechatAccount.branchName = dg[index++, i].Value.ToString(); //agentWechatAccount.type = "直供渠道联系人"; } else if (dg.Columns[0].HeaderText.Equals("代理商编号")) { agentWechatAccount.agentNo = dg[index++, i].Value.ToString(); agentWechatAccount.agentName = dg[index++, i].Value.ToString(); if (dg.Columns[2].HeaderText.Equals("渠道编码")) { agentWechatAccount.branchNo = dg[index++, i].Value.ToString(); agentWechatAccount.branchName = dg[index++, i].Value.ToString(); } } agentWechatAccount.contactEmail = dg[index++, i].Value.ToString(); agentWechatAccount.contactId = dg[index++, i].Value.ToString(); agentWechatAccount.contactName = dg[index++, i].Value.ToString(); agentWechatAccount.contactTel = dg[index++, i].Value.ToString(); agentWechatAccount.contactWechat = dg[index++, i].Value.ToString(); agentWechatAccount.feeRight = dg[index++, i].Value.ToString(); agentWechatAccount.policyRight = dg[index++, i].Value.ToString(); agentWechatAccount.performanceRight = dg[index++, i].Value.ToString(); agentWechatAccount.studyRight = dg[index++, i].Value.ToString(); agentWechatAccount.complainRight = dg[index++, i].Value.ToString(); agentWechatAccount.monitorRight = dg[index++, i].Value.ToString(); agentWechatAccount.errorRight = dg[index++, i].Value.ToString(); agentWechatAccount.contactRight = dg[index++, i].Value.ToString(); if (String.IsNullOrEmpty(agentWechatAccount.branchNo)) agentWechatAccount.branchNo = ""; if (AgentNoList.Contains(agentWechatAccount.contactId) && !type.Equals("代理商联系人")) { continue; } if (WechatNoList.Contains(agentWechatAccount.contactWechat) && !type.Equals("代理商联系人")) { continue; } agentWechatAccountDao.Delete(agentWechatAccount.contactId); agentWechatAccountDao.Add(agentWechatAccount); } }