/// <summary> /// 已纳税人导入方式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, EventArgs e) { if (checkItemsInFile()) { ExcelHelper excel = new ExcelHelper(); try { excel.OpenFile(txtDir.Text, 1, true); int rows = excel.GetRowsCount(); int i = 2; for (; i <= rows; i++) //check first { List <string> sl = excel.GetValue(i, 1, i, 5); int acid = SysUtil.GetAgentCID(sl[0], sl[1]); if (acid == -1) { MessageBox.Show(sl[1] + "国别记录不存在,请检查", this.funName); //excel.Close(); return; } if (db.TAX_PLAYERs.SingleOrDefault(a => (a.TP_ACID == acid) && (a.TP_NAME == sl[2].Replace(" ", string.Empty))) != null) { MessageBox.Show(sl[2] + "此纳税人已存在,请检查", this.funName); //excel.Close(); return; } } i = 2; for (; i <= rows; i++) { List <string> sl = excel.GetValue(i, 1, i, 5); TAX_PLAYER tp = new TAX_PLAYER { TP_ACID = SysUtil.GetAgentCID(sl[0], sl[1]), TP_AIID = SysUtil.GetAgentID(sl[0]), TP_NAME = sl[2].Replace(" ", string.Empty), TP_ENNAME = sl[3], TP_IDNUMBER = sl[4], }; db.TAX_PLAYERs.InsertOnSubmit(tp); } db.SubmitChanges(); //excel.Close(); loadPlayers(); MessageBox.Show("导入成功,导入记录" + (rows - 1) + "条", this.funName); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { excel.Close(); } } }
private void benNew_Click(object sender, EventArgs e) { if (!checkInput()) { MessageBox.Show("请检查输入项", this.funName, MessageBoxButtons.OK); } //新建 if (this.Flag == "NEW") { AGENT_INFO ai = new AGENT_INFO { AI_NAME = txtName.Text.Trim(), AI_ADDRESS = txtAddress.Text.Trim(), AI_INDUSTRY = txtIndustry.Text.Trim(), AI_POSTCODE = txtPostCode.Text.Trim(), AI_TAXCODEID = txtTaxCodeID.Text.Trim(), AI_TAXID = txtTAXID.Text.Trim(), AI_TAXNAME = txtTaxName.Text.Trim(), AI_TEL = txtTel.Text.Trim(), AI_ISDEL = false, }; if (cbxTempName.SelectedIndex != -1) { ai.AI_TIID = ((TEMPLATE_INFO)cbxTempName.SelectedItem).TI_ID; } db.AGENT_INFOs.InsertOnSubmit(ai); db.SubmitChanges(); this.DialogResult = System.Windows.Forms.DialogResult.OK; MessageBox.Show("添加成功"); } else //修改 { AGENT_INFO ai = db.AGENT_INFOs.Where(a => a.AI_ID == this.AgentID).SingleOrDefault(); if (ai != null) { ai.AI_NAME = txtName.Text.Trim(); ai.AI_ADDRESS = txtAddress.Text.Trim(); ai.AI_INDUSTRY = txtIndustry.Text.Trim(); ai.AI_POSTCODE = txtPostCode.Text.Trim(); ai.AI_TAXCODEID = txtTaxCodeID.Text.Trim(); ai.AI_TAXID = txtTAXID.Text.Trim(); ai.AI_TAXNAME = txtTaxName.Text.Trim(); ai.AI_TEL = txtTel.Text.Trim(); ai.AI_ISDEL = false; if (cbxTempName.SelectedIndex != -1) { ai.AI_TIID = ((TEMPLATE_INFO)cbxTempName.SelectedItem).TI_ID; } db.SubmitChanges(); this.DialogResult = System.Windows.Forms.DialogResult.OK; MessageBox.Show("修改成功"); } } }
/// <summary> /// 修改模板 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { try { if (!CheckInput()) { MessageBox.Show("请检查输入项", this.funName, MessageBoxButtons.OK); } int tmpid = 0; if (this.flag == "NEW") //insert { InsertNewTemplate(ref tmpid); //新建 if (tmpid != 0) { MessageBox.Show("添加成功"); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } } else if (this.flag == "UPDATE") { TEMPLATE_INFO lti = db.TEMPLATE_INFOs.SingleOrDefault(t => t.TI_ID == this.tiidtmp); //TODO ,should be single or default lti.TI_ISVALID = false; List <TEMPLATE_COLUMN> lTC = db.TEMPLATE_COLUMNs.Where(tc => tc.TC_TIID == lti.TI_ID).Select(a => a).ToList(); foreach (var detail in lTC) { db.TEMPLATE_COLUMNs.DeleteOnSubmit(detail); } db.SubmitChanges(); InsertNewTemplate(ref tmpid); //update ac tmpid to the new one var lac = db.AGENT_COUNTRies.Where(a => a.AC_TIID == lti.TI_ID).Select(l => l); foreach (var d in lac) { d.AC_TIID = tmpid; } db.SubmitChanges(); MessageBox.Show("保存成功", this.funName, MessageBoxButtons.OK); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, this.funName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> ///新建或更改角色信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { if (checkisok() == true) { if (db.GROUP_INFOs.Count(q => q.GI_NAME == txtRoleName.Text) == 0) //新建 { GROUP_INFO gi = new GROUP_INFO { GI_NAME = txtRoleName.Text.Trim() }; db.GROUP_INFOs.InsertOnSubmit(gi); db.SubmitChanges(); //配置权限 foreach (var i in lbxYes.Items) { GROUP_AUTHORITY ga = new GROUP_AUTHORITY { GA_GIID = gi.GI_ID, GA_ALNAME = i.ToString() }; db.GROUP_AUTHORITies.InsertOnSubmit(ga); } db.SubmitChanges(); MessageBox.Show("添加成功!"); } else //修改 { var gi = db.GROUP_INFOs.First(q => q.GI_NAME == txtRoleName.Text); //权限更改 var deleteOrderDetails = db.GROUP_AUTHORITies.Where(p => p.GA_GIID == gi.GI_ID); foreach (var detail in deleteOrderDetails) { db.GROUP_AUTHORITies.DeleteOnSubmit(detail); } //db.SubmitChanges(); foreach (var i in lbxYes.Items) { GROUP_AUTHORITY ga = new GROUP_AUTHORITY { GA_GIID = gi.GI_ID, GA_ALNAME = i.ToString() }; db.GROUP_AUTHORITies.InsertOnSubmit(ga); } db.SubmitChanges(); MessageBox.Show("修改成功!"); } loadRoles(); } }
/// <summary> /// 修改密码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (txtNew.Text.Trim() == "" || txtOld.Text.Trim() == "" || txtReNew.Text.Trim() == "") { MessageBox.Show("密码为空,请检查"); return; } if (txtNew.Text.Trim() != txtReNew.Text.Trim()) { MessageBox.Show("两次新密码不一致,请检查"); return; } var u = db.USER_INFOs.Where(a => a.UI_ID == SysUtil.CurrentUserID() && a.UI_PASSWORD == MD5Util.GetHash(txtOld.Text)).SingleOrDefault(); if (u != null) { u.UI_PASSWORD = MD5Util.GetHash(txtReNew.Text.Trim()); db.SubmitChanges(); MessageBox.Show("密码修改成功"); } else { MessageBox.Show("原密码有误,请检查"); return; } }
/// <summary> /// 原始数据放入数据库,返回批次ID,由报表窗口调用 /// </summary> /// <returns></returns> public int WriteToDB() { //create BathNUM first BATCH_INFO bi = new BATCH_INFO { BI_IMPORTTIME = DateTime.Now, BI_ISDEL = false, BI_TIID = this.TIID, BI_UIID = SysUtil.CurrentUserID(), }; db.BATCH_INFOs.InsertOnSubmit(bi); db.SubmitChanges(); for (int i = 0; i < dgvSals.SelectedRows.Count; i++) { TEMPLATE_INFO ti = db.TEMPLATE_INFOs.SingleOrDefault(a => a.TI_ID == this.TIID); string cols = string.Format("SI_BIID,{0}", ti.TI_COLSINORDER); var value = new List <string>(); value.Add(bi.BI_ID.ToString()); for (int index = 0; index < ti.TI_COLSCOUNT; index++) { value.Add("'" + dgvSals.SelectedRows[i].Cells[index + 9].Value.ToString() + "'"); } ColumnsDAL cd = new ColumnsDAL(); cd.OpenConnection(System.Configuration.ConfigurationManager.ConnectionStrings["TaxDemo.Properties.Settings.testdbConnectionString"].ConnectionString); cd.WriteRawData(value, cols); cd.CloseConnection(); } return(bi.BI_ID); }
/// <summary> /// 删除1条列数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDel_Click(object sender, EventArgs e) { if (dgvCols.SelectedRows.Count != 1) { MessageBox.Show("请选择一条记录后进行操作", funName, MessageBoxButtons.OK); return; } DialogResult dialogResult = MessageBox.Show("确定删除此列吗", funName, MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int aid = (int)dgvCols.SelectedRows[0].Cells[0].Value; var agent = db.COLUMNS_INFOs.Where(ai => ai.CI_ID == aid).Select(a => a).Single(); agent.CI_ISVALID = false; db.SubmitChanges(); MessageBox.Show("删除成功", funName, MessageBoxButtons.OK); loadCols(); } }
/// <summary> /// 新建或更改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNew_Click(object sender, EventArgs e) { if (!checkInput()) { MessageBox.Show("请检查输入项", this.funName, MessageBoxButtons.OK); return; } if (this.Flag == "NEW") { var d = db.AGENT_COUNTRies.SingleOrDefault(a => (a.AC_AIID == ((AGENT_INFO)cbxAgents.SelectedItem).AI_ID && a.AC_NAME == txtCountry.Text.Trim())); if (d != null) { MessageBox.Show("此条记录已存在,请检查"); return; } AGENT_COUNTRY ac = new AGENT_COUNTRY { AC_AIID = ((AGENT_INFO)cbxAgents.SelectedItem).AI_ID, AC_ISDEL = false, AC_CURRENCY = ((CURRENCY)cbxCurrency.SelectedItem).C_NAME, AC_NAME = txtCountry.Text.Trim(), AC_TIID = ((TEMPLATE_INFO)cbxTempName.SelectedItem).TI_ID, }; db.AGENT_COUNTRies.InsertOnSubmit(ac); db.SubmitChanges(); MessageBox.Show("添加成功", this.funName, MessageBoxButtons.OK); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { AGENT_COUNTRY ac = db.AGENT_COUNTRies.Where(a => a.AC_ID == ACID).SingleOrDefault(); ac.AC_CURRENCY = ((CURRENCY)cbxCurrency.SelectedItem).C_NAME; ac.AC_NAME = txtCountry.Text.Trim(); ac.AC_TIID = ((TEMPLATE_INFO)cbxTempName.SelectedItem).TI_ID; db.SubmitChanges(); MessageBox.Show("修改成功", this.funName, MessageBoxButtons.OK); this.DialogResult = System.Windows.Forms.DialogResult.OK; } }
/// <summary> /// 新建或更改用户信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { if (!isInputValid()) { MessageBox.Show("请检查输入项!"); return; } var gi = from g in db.GROUP_INFOs where g.GI_NAME == cbxRoles.SelectedItem.ToString() select g; if (txtUserName.ReadOnly == false) //新建 { USER_INFO u = new USER_INFO { UI_ISVALID = cbxIsValid.Checked, UI_MAIL = txtMail.Text.Trim(), UI_NAME = txtUserName.Text.Trim(), UI_TEL = txtTel.Text.Trim(), UI_PASSWORD = MD5Util.GetHash("123456"), //txtUserName.Text.Trim() UI_TRUENAME = txtTrueName.Text.Trim(), UI_GIID = gi.First().GI_ID }; db.USER_INFOs.InsertOnSubmit(u); } else //更改 { var user = db.USER_INFOs.Where(u => u.UI_NAME == txtUserName.Text).SingleOrDefault(); user.UI_GIID = gi.First().GI_ID; user.UI_ISVALID = cbxIsValid.Checked; user.UI_MAIL = txtMail.Text.Trim(); user.UI_TEL = txtTel.Text.Trim(); user.UI_TRUENAME = txtTrueName.Text.Trim(); } db.SubmitChanges(); MessageBox.Show("数据提交成功!"); loadUsers(); txtUserName.ReadOnly = true; }
/// <summary> /// 设置为当前年度 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SetcurrentYear(object sender, EventArgs e) { if (dgvYear.SelectedRows.Count != 1) { MessageBox.Show("请选择一行后进行操作", this.funName); return; } using (TAXDBDataContext db = new TAXDBDataContext()) { AGENT_YEAR old = db.AGENT_YEARs.SingleOrDefault(a => a.AY_ISCURRENT == true); if (old != null) { old.AY_ISCURRENT = false; } db.SubmitChanges(); AGENT_YEAR ay = db.AGENT_YEARs.SingleOrDefault(a => a.AY_ID == (int)dgvYear.SelectedRows[0].Cells[0].Value); ay.AY_ISCURRENT = true; db.SubmitChanges(); loadYears(); MessageBox.Show("修改成功", this.funName); } }
private void btnAdd_Click(object sender, EventArgs e) { //new Col gbx2.Enabled = false; COLUMNS_ALIA a = new COLUMNS_ALIA { CA_CIID = this.ColID, CA_ALIAS = txtTitleAlias.Text.Trim() }; db.COLUMNS_ALIAs.InsertOnSubmit(a); db.SubmitChanges(); MessageBox.Show("添加成功", this.funName, MessageBoxButtons.OK, MessageBoxIcon.Information); loadColAlias(); gbx2.Enabled = true; }
/// <summary> /// 删除公司 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDel_Click(object sender, EventArgs e) { if (dgvAgents.SelectedRows.Count != 1) { MessageBox.Show("请选择一条记录后进行操作", this.funName, MessageBoxButtons.OK); return; } DialogResult dialogResult = MessageBox.Show("确定删除此记录吗", "公司信息管理", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int aid = (int)dgvAgents.SelectedRows[0].Cells[0].Value; var agent = db.AGENT_INFOs.Where(ai => ai.AI_ID == aid).Select(a => a).Single(); agent.AI_ISDEL = true; db.SubmitChanges(); MessageBox.Show("删除成功", "公司信息管理", MessageBoxButtons.OK); loadAgents(); } }
/// <summary> /// 新增年度 /// </summary> private void addYear() { if (!checkInput()) { MessageBox.Show("请检查输入项", this.funName); return; } using (TAXDBDataContext db = new TAXDBDataContext()) { AGENT_YEAR ay = new AGENT_YEAR { AY_NAME = Convert.ToInt32(txtYear.Text.Trim()), AY_ADDTIME = DateTime.Now, AY_UIID = SysUtil.CurrentUserID(), }; db.AGENT_YEARs.InsertOnSubmit(ay); db.SubmitChanges(); loadYears(); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (checkInput() != true) { MessageBox.Show("请检查输入项", this.funName, MessageBoxButtons.OK); return; } if (this.Flag == "NEW") //新建 { TAX_PLAYER t = db.TAX_PLAYERs.SingleOrDefault(a => (a.TP_ACID == ((AGENT_COUNTRY)cbxAgentCs.SelectedItem).AC_ID) && (a.TP_NAME == txtName.Text.Trim())); if (t != null) { MessageBox.Show(this.funName, "此人已在该国别中存在,请检查", MessageBoxButtons.OK); return; } TAX_PLAYER tp = new TAX_PLAYER { TP_NAME = txtName.Text.Trim(), TP_ENNAME = txtEnName.Text.Trim(), TP_IDNUMBER = txtID.Text.Trim(), TP_AIID = (int)cbxAgents.SelectedValue, TP_ACID = ((AGENT_COUNTRY)cbxAgentCs.SelectedItem).AC_ID }; db.TAX_PLAYERs.InsertOnSubmit(tp); } else if (this.Flag == "UPDATE") //修改 { TAX_PLAYER tp = db.TAX_PLAYERs.Single(a => a.TP_ID == this.TaxPlayerID); if (tp != null) { tp.TP_NAME = txtName.Text.Trim(); tp.TP_ENNAME = txtEnName.Text.Trim(); tp.TP_IDNUMBER = txtID.Text.Trim(); tp.TP_AIID = (int)cbxAgents.SelectedValue; tp.TP_ACID = ((AGENT_COUNTRY)cbxAgentCs.SelectedItem).AC_ID; } } db.SubmitChanges(); this.DialogResult = System.Windows.Forms.DialogResult.OK; }
/// <summary> /// 增加货币单位 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddCurr_Click(object sender, EventArgs e) { if (!checkInputOfCurrency()) { MessageBox.Show("请检查输入项"); return; } using (TAXDBDataContext db = new TAXDBDataContext()) { //db.Connection.ConnectionString = Cryptogram.DecryptPassword(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString()); CURRENCY curr = new CURRENCY { C_ADDTIME = DateTime.Now, C_NAME = txtCurrency.Text.Trim(), C_UIID = SysUtil.CurrentUserID(), C_ISDEL = false }; db.CURRENCies.InsertOnSubmit(curr); db.SubmitChanges(); loadCurrency(); MessageBox.Show("添加成功"); } }
/// <summary> /// 删除模板 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDel_Click(object sender, EventArgs e) { if (dgvTemplates.SelectedRows.Count != 1) { MessageBox.Show("请选择一条记录后进行操作", funName, MessageBoxButtons.OK); return; } DialogResult dialogResult = MessageBox.Show("确定删除此列吗", funName, MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int tid = (int)dgvTemplates.SelectedRows[0].Cells[0].Value; TEMPLATE_INFO lti = db.TEMPLATE_INFOs.SingleOrDefault(t => t.TI_ID == tid); //TODO ,should be single or default lti.TI_ISVALID = false; List <TEMPLATE_COLUMN> lTC = db.TEMPLATE_COLUMNs.Where(tc => tc.TC_TIID == lti.TI_ID).Select(a => a).ToList(); foreach (var detail in lTC) { db.TEMPLATE_COLUMNs.DeleteOnSubmit(detail); } db.SubmitChanges(); MessageBox.Show("删除成功", funName, MessageBoxButtons.OK); loadTemplates(); } }
/// <summary> /// 导入留抵记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, EventArgs e) { if (cbxAgentCs.SelectedItem == null) { MessageBox.Show("请选择国别信息后进行导入"); return; } int acid = ((AGENT_COUNTRY)cbxAgentCs.SelectedItem).AC_ID; if (checkItemsInFile()) { ExcelHelper excel = new ExcelHelper(); try { excel.OpenFile(txtDir.Text, 1, true); int rows = excel.GetRowsCount(); int i = 2; List <string> sl; for (; i <= rows; i++) //首先检查纳税人和对应年份的留抵记录是否已存在 { sl = excel.GetValue(i, 1, i, 5); string tname = sl[0].Replace(" ", string.Empty); int year = Convert.ToInt32(sl[1].Replace(" ", string.Empty)); if (db.TAX_PLAYERs.SingleOrDefault(a => (a.TP_ACID == acid) && (a.TP_NAME == tname)) == null) { MessageBox.Show(tname + "此纳税人不存在,请检查", this.funName); //excel.Close(); return; } if (db.v_TAXCREDITs.SingleOrDefault(a => a.TC_YEAR == year && a.TP_NAME == tname) != null) { MessageBox.Show(tname + "此纳税人" + year + "留抵记录已存在,请检查", this.funName); //excel.Close(); return; } } i = 2; for (; i <= rows; i++) { sl = excel.GetValue(i, 1, i, 5); string tname = sl[0].Replace(" ", string.Empty); int year = Convert.ToInt32(sl[1].Replace(" ", string.Empty)); int tpid = SysUtil.GetPlayerID(acid, tname); if (sl[2] == string.Empty) { sl[2] = "0"; } if (sl[3] == string.Empty) { sl[3] = "0"; } if (sl[4] == string.Empty) { sl[4] = "0"; } TAX_CREDIT tc = new TAX_CREDIT { TP_ID = tpid, TC_YEAR = year, TC_CREDITALL = Math.Abs(Convert.ToDecimal(sl[2])), TC_CREDITUSED = Math.Abs(Convert.ToDecimal(sl[3])), TC_CREDITBALANCE = Math.Abs(Convert.ToDecimal(sl[4])) }; db.TAX_CREDITs.InsertOnSubmit(tc); } db.SubmitChanges(); MessageBox.Show("导入成功,导入记录" + (rows - 1) + "条", this.funName); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { excel.Close(); } } }
private void btnDel_Click(object sender, EventArgs e) { int count = dgvReportList.SelectedRows.Count; if (count == 0) { MessageBox.Show("请选择记录后进行操作"); return; } DialogResult dialogResult = MessageBox.Show("确定将此" + count + "记录删除吗", this.funName, MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { for (int i = 0; i < count; i++) { /* Modified by cyq 20160331 */ /* *********** Begin *********/ //int riid = (int)dgvReportList.SelectedRows[i].Cells[0].Value; //db.REPORT1_DETAILs.DeleteAllOnSubmit(db.REPORT1_DETAILs.Where(a => a.R1_RIID == riid)); //db.REPORT2_DETAILs.DeleteAllOnSubmit(db.REPORT2_DETAILs.Where(a => a.R2_RIID == riid)); //db.REPORT_INFOs.DeleteAllOnSubmit(db.REPORT_INFOs.Where(a => a.RI_ID == riid)); //db.TAX_CREDITs.DeleteAllOnSubmit(db.TAX_CREDITs.Where(a => a.TC_RIID == riid)); //db.SubmitChanges(); int riid = (int)dgvReportList.SelectedRows[i].Cells[0].Value; try { db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); var reportInfo = db.REPORT_INFOs.Where(a => a.RI_ID == riid); var tpid = reportInfo.Select(report => report.RI_TPID).Single(); var relatedCredits = db.TAX_CREDITs .Where(a => a.TP_ID == tpid && (SysUtil.GetCurrentYear() - a.TC_YEAR) <= 5 && a.TC_CREDITUSED > 0).ToList(); if (relatedCredits.Any()) { decimal avail = reportInfo.Single().RI_USEALL.GetValueOrDefault() - reportInfo.Single().RI_USE2.GetValueOrDefault(); decimal diff = 0; foreach (var credit in relatedCredits) { diff = credit.TC_CREDITUSED.GetValueOrDefault() - avail; if (diff >= 0) { credit.TC_CREDITUSED -= avail; credit.TC_CREDITBALANCE += avail; break; } else { avail -= credit.TC_CREDITUSED.GetValueOrDefault(); credit.TC_CREDITBALANCE = credit.TC_CREDITALL; credit.TC_CREDITUSED = 0; } } } db.REPORT1_DETAILs.DeleteAllOnSubmit(db.REPORT1_DETAILs.Where(a => a.R1_RIID == riid)); db.REPORT2_DETAILs.DeleteAllOnSubmit(db.REPORT2_DETAILs.Where(a => a.R2_RIID == riid)); db.REPORT_INFOs.DeleteAllOnSubmit(reportInfo); db.TAX_CREDITs.DeleteAllOnSubmit(db.TAX_CREDITs.Where(a => a.TC_RIID == riid)); db.SubmitChanges(ConflictMode.FailOnFirstConflict); db.Transaction.Commit(); } catch (ChangeConflictException) { db.Transaction.Rollback(); MessageBox.Show("报表记录及报表对应的留抵因未知原因无法级联删除。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } /* *********** End *********/ } } LoadData(); }
} // end method InitReport2 /// <summary> /// 报表数据入库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { //入库前检查是否已存在 var tmp = db.REPORT_INFOs.SingleOrDefault(a => a.RI_AYNAME == RW1.Base.RI_AYNAME && a.RI_ACID == RW1.Base.RI_ACID && a.RI_TPID == RW1.Base.RI_TPID); if (tmp != null) { MessageBox.Show("相同记录已存在,请检查", this.funName); return; } //若使用留抵数据,先进行留抵记录的操作 if (RW1.Base.RI_USEALL != null && RW1.Base.RI_USEALL > 0) { if (CheckCredit(RW1.Base.RI_TPID, RW1.Base.RI_AYNAME, (decimal)RW1.Base.RI_USEALL, (decimal)RW1.Base.RI_USE2) == false) { MessageBox.Show(string.Format("可用抵扣额不足{0}", (decimal)RW1.Base.RI_USEALL)); return; } else { var list = db.TAX_CREDITs.Where(a => a.TP_ID == RW1.Base.RI_TPID && (RW1.Base.RI_AYNAME - a.TC_YEAR) <= 5 && a.TC_CREDITBALANCE > 0).OrderBy(l => l.TC_YEAR).ToList(); decimal tmpBlance = (decimal)RW1.Base.RI_USEALL - (decimal)RW1.Base.RI_USE2; foreach (var l in list) { decimal tt = l.TC_CREDITBALANCE; if (tmpBlance >= l.TC_CREDITBALANCE) { l.TC_CREDITBALANCE = 0; l.TC_CREDITUSED += tt; tmpBlance = tmpBlance - tt; } else { l.TC_CREDITBALANCE -= tmpBlance; l.TC_CREDITUSED += tmpBlance; tmpBlance = 0; } } db.SubmitChanges(); } } //若需补税,计算倒推数据 if (RW1.Base.RI_NEEDPACKREAL > 0) { TAX_RATE tr = db.TAX_RATEs.Where(r => RW1.Base.RI_NEEDPACKREAL >= r.TR_MIN && RW1.Base.RI_NEEDPACKREAL < r.TR_MAX).SingleOrDefault(); RW1.Base.RI_BACKRATEID = tr.TR_ID; RW1.Base.RI_BACKMINUS = RW1.MINUS; RW1.Base.RI_BACKTAXQUICK = tr.TR_QUICH; RW1.Base.RI_BACKTAXRATE = tr.TR_RATE; RW1.Base.RI_BACKSUMTAXSALARY = ((decimal)(RW1.Base.RI_NEEDPACKREAL + tr.TR_QUICH) * 100 / tr.TR_RATE); RW1.Base.RI_BACKSUMSALARY = RW1.Base.RI_BACKSUMTAXSALARY + RW1.Base.RI_BACKMINUS; } //报表入库 int BID = ((frmImportSalary)(this.Owner)).WriteToDB(); RW1.Base.RI_BIID = BID; db.REPORT_INFOs.InsertOnSubmit(RW1.Base); //入库 db.SubmitChanges(); //计算本年度的可用抵扣 insert到credit历史中 /* Modified by cyq 20160331 */ /* *********** Begin *********/ //if (RW1.Base.RI_SUMTAXALREADYRMB > (RW1.Base.RI_SUMTAXRMB + RW1.Base.RI_USEALL)) //{ // TAX_CREDIT tc = new TAX_CREDIT // { // TC_YEAR = RW1.Base.RI_AYNAME, // TC_RIID = RW1.Base.RI_ID, // TC_CREDITALL = (decimal)(RW1.Base.RI_SUMTAXALREADYRMB + RW1.Base.RI_USEALL) - (RW1.Base.RI_SUMTAXRMB), //(decimal)(RW1.Base.RI_SUMTAXALREADYRMB - (RW1.Base.RI_SUMTAXRMB + RW1.Base.RI_USEALL)), // TC_CREDITUSED = 0, // TC_CREDITBALANCE = (decimal)(RW1.Base.RI_SUMTAXALREADYRMB + RW1.Base.RI_USEALL) - (RW1.Base.RI_SUMTAXRMB)//(decimal)(RW1.Base.RI_SUMTAXALREADYRMB - (RW1.Base.RI_SUMTAXRMB + RW1.Base.RI_USEALL)) // }; // db.TAX_CREDITs.InsertOnSubmit(tc); // db.SubmitChanges(); //} if (AddedTC != null) { AddedTC.TC_RIID = RW1.Base.RI_ID; if (RW2.Base.RI_USE2.HasValue) { if (AddedTC.TC_CREDITALL != 0) { AddedTC.TC_CREDITALL += RW2.Base.RI_USE2.Value; AddedTC.TC_CREDITBALANCE += RW2.Base.RI_USE2.Value; } else { if (RW2.Base.RI_USE2.Value - RW2.Base.RI_NEEDPACK > 0) { AddedTC.TC_CREDITALL += RW2.Base.RI_USE2.Value - RW2.Base.RI_NEEDPACK; AddedTC.TC_CREDITBALANCE += RW2.Base.RI_USE2.Value - RW2.Base.RI_NEEDPACK; } } } db.TAX_CREDITs.InsertOnSubmit(AddedTC); db.SubmitChanges(); } /* *********** End *********/ foreach (var d in RW1.Details) { d.R1_RIID = RW1.Base.RI_ID; } foreach (var d in RW2.Details) { d.R2_RIID = RW1.Base.RI_ID; } db.REPORT1_DETAILs.InsertAllOnSubmit(RW1.Details); //入库报表1 db.REPORT2_DETAILs.InsertAllOnSubmit(RW2.Details); //入库报表2 db.SubmitChanges(); ((frmImportSalary)(this.Owner)).RemoveData(); //入库后,原窗口将数据从表格中删除 MessageBox.Show("入库成功", this.funName); }