private void btnSave_Click(object sender, EventArgs e) { outputAgentInvoice.agentName = this.txtAgentName.Text; outputAgentInvoice.agentNo = this.txtAgentNo.Text; outputAgentInvoice.comment = this.txtComment.Text; outputAgentInvoice.invoiceContent = this.txtContent.Text; outputAgentInvoice.invoiceDate = this.txtDate.Text; outputAgentInvoice.invoiceFee = this.txtFee.Text; outputAgentInvoice.invoiceNo = this.txtInvoiceNo.Text; outputAgentInvoice.invoiceType = this.txtInvoiceType.Text; outputAgentInvoice.invoiceMonth = this.txtMonth.Text; AgentInvoiceDao agentInvoiceDao = new AgentInvoiceDao(); int i = agentInvoiceDao.Update(outputAgentInvoice); if (i >= 0) { MessageBox.Show("修改完成"); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("修改失败"); } }
private void prepareGrid(string agentNo,string agentName, string invoiceMonth) { this.Cursor = Cursors.WaitCursor; AgentInvoiceDao agentInvoiceDao = new AgentInvoiceDao(); IList<AgentInvoice> agentInvoiceList = new List<AgentInvoice>(); agentInvoiceList = agentInvoiceDao.GetList(agentNo,agentName,invoiceMonth); if (agentInvoiceList != null && agentInvoiceList.Count > 0) { this.grpList.Text = "发票记录列表(" + agentInvoiceList.Count + ")"; this.dgInvoice.Rows.Clear(); dgInvoice.Columns.Clear(); dgInvoice.Columns.Add("月份", "月份"); dgInvoice.Columns.Add("收票日期", "收票日期"); dgInvoice.Columns.Add("代理商编号", "代理商编号"); dgInvoice.Columns.Add("代理商全称", "代理商全称"); dgInvoice.Columns.Add("内容", "内容"); dgInvoice.Columns.Add("金额", "金额"); dgInvoice.Columns.Add("发票类型", "发票类型"); dgInvoice.Columns.Add("发票号", "发票号"); dgInvoice.Columns.Add("备注", "备注"); for (int i = 0; i < agentInvoiceList.Count; i++) { dgInvoice.Rows.Add(); DataGridViewRow row = dgInvoice.Rows[i]; row.Cells[0].Value = agentInvoiceList[i].invoiceMonth; row.Cells[1].Value = agentInvoiceList[i].invoiceDate; row.Cells[2].Value = agentInvoiceList[i].agentNo; row.Cells[3].Value = agentInvoiceList[i].agentName; row.Cells[4].Value = agentInvoiceList[i].invoiceContent; row.Cells[5].Value = agentInvoiceList[i].invoiceType; row.Cells[6].Value = agentInvoiceList[i].invoiceFee; row.Cells[7].Value = agentInvoiceList[i].invoiceNo; row.Cells[8].Value = agentInvoiceList[i].comment; } dgInvoice.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgInvoice.AutoResizeColumns(); } this.Cursor = Cursors.Default; }
/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(3, "开始导入发票信息...\r\n"); //导入代理商 WechatAction wechatAction = new WechatAction(); AgentInvoiceDao agentInvoiceDao = new AgentInvoiceDao(); AgentDao agentDao = new AgentDao(); for (int i = 0; i < dgInvoice.RowCount; i++) { AgentInvoice agentInvoice = new AgentInvoice(); agentInvoice.invoiceMonth = dgInvoice[0, i].Value.ToString(); agentInvoice.invoiceDate = DateTime.Parse( dgInvoice[1, i].Value.ToString()).ToString("yyyy-MM-dd"); agentInvoice.agentNo = dgInvoice[2, i].Value.ToString(); agentInvoice.agentName = dgInvoice[3, i].Value.ToString(); agentInvoice.invoiceContent = dgInvoice[4, i].Value.ToString(); agentInvoice.invoiceFee = dgInvoice[5, i].Value.ToString(); agentInvoice.invoiceType = dgInvoice[6, i].Value.ToString(); agentInvoice.invoiceNo = dgInvoice[7, i].Value.ToString(); agentInvoice.comment = dgInvoice[8, i].Value.ToString(); Agent agent = agentDao.Get(agentInvoice.agentNo); if (agent != null && !String.IsNullOrEmpty(agent.agentName)) { agentInvoiceDao.Delete(agentInvoice); agentInvoiceDao.Add(agentInvoice); dgInvoice["result", i].Value = "导入成功"; String message = String.Format(Settings.Default.Invoice_Wechat_Message, agentInvoice.invoiceDate, agentInvoice.invoiceContent, agentInvoice.invoiceFee, agentInvoice.invoiceType, agentInvoice.invoiceNo,agentInvoice.comment); wechatAction.sendTextMessageToWechat(agentInvoice.agentNo, message, Settings.Default.Wechat_Secret, Settings.Default.Wechar_Invoice_AppId); } else { dgInvoice["result", i].Value = "导入失败,代理商编号:" + agentInvoice.agentNo+"不存在,请先导入代理商."; } } //dgInvoice.AutoResizeColumns(); worker.ReportProgress(4, "导入发票信息完成...\r\n"); //MessageBox.Show("数据上传完毕"); }