private void btnDel_Click(object sender, EventArgs e) { try { try { gridView返利单.FocusedRowHandle -= 1; gridView返利单.FocusedRowHandle += 1; } catch { } string sErr = ""; int iCou = 0; SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { if (txt单据号.Text.Trim() == "") { throw new Exception("请选择单据"); } string sSQL = @" select * from [dbo].[_高开返利核销单_SZ] where cCode = '{0}' "; sSQL = string.Format(sSQL, txt单据号.Text.Trim()); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("单据不存在"); } DAL._高开返利核销单_SZ dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利核销单_SZ(); sSQL = dal.Delete(txt单据号.Text.Trim()); iCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); tran.Commit(); if (iCou > 0) { MessageBox.Show("删除成功"); SetNull(); } } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "删除失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
private void btnSave_Click(object sender, EventArgs e) { try { try { gridView返利单.FocusedRowHandle -= 1; gridView返利单.FocusedRowHandle += 1; } catch { } if (txt开票金额.Text.Trim() == "" && BaseFunction.ReturnDecimal(txt开票金额.Text.Trim()) == 0) { txt开票金额.Focus(); throw new Exception("请设置开票金额"); } if (txt考核金额.Text.Trim() == "" && BaseFunction.ReturnDecimal(txt考核金额.Text.Trim()) == 0) { txt考核金额.Focus(); throw new Exception("请设置考核金额"); } if (txt费率.Text.Trim() == "" && BaseFunction.ReturnDecimal(txt费率.Text.Trim()) == 0) { txt费率.Focus(); throw new Exception("请设置费率"); } int iCou = 0; string sErr = ""; string s_Guid = Guid.NewGuid().ToString(); Guid sGuid = Guid.NewGuid(); SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { int iCode = 0; string sSQL = ""; if (txt单据号.Text.Trim() != "") { sSQL = @" select * from [dbo].[_高开返利核销单_SZ] where cCode = '{0}' "; sSQL = string.Format(sSQL, txt单据号.Text.Trim()); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { iCode = 0; } else { if (dt.Rows[0]["auditUid"].ToString().Trim() != "") { throw new Exception("单据已经审核"); } sSQL = @" delete [_高开返利核销单_SZ] where cCode = '{0}' "; sSQL = string.Format(sSQL, txt单据号.Text.Trim()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } sSQL = @" select max(cCode) as cCodeMax from [dbo].[_高开返利核销单_SZ] where cCode like '{0}%' "; sSQL = string.Format(sSQL, dtm.DateTime.ToString("yyyyMM")); DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtCode == null || dtCode.Rows.Count == 0 || dtCode.Rows[0]["cCodeMax"].ToString().Trim() == "") { iCode = 1; } else { string sCodeTemp = dtCode.Rows[0]["cCodeMax"].ToString().Trim(); string stemp = sCodeTemp.Substring(6); iCode = BaseFunction.ReturnInt(stemp) + 1; } string sCode = iCode.ToString().Trim(); sCode = dtm.DateTime.ToString("yyyyMM") + sCode.PadLeft(4, '0'); for (int i = 0; i < gridView返利单.RowCount; i++) { if (!BaseFunction.ReturnBool(gridView返利单.GetRowCellValue(i, gridColbchoose))) { continue; } Model._高开返利核销单_SZ model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利核销单_SZ(); model.DLS = lookUpEditcCusCode.EditValue.ToString().Trim(); if (lookUpEdit区域.EditValue != null) { model.QY = lookUpEdit区域.EditValue.ToString().Trim(); } model.cCode = sCode; model.dtmDate = DateTime.Today; model.dMoney_kh = BaseFunction.ReturnDecimal(txt考核金额.Text.Trim()); model.dMoney_fl = BaseFunction.ReturnDecimal(txt费率.Text.Trim()); model.dMoney_kp = BaseFunction.ReturnDecimal(txt开票金额.Text.Trim()); model.FLD_iID = BaseFunction.ReturnLong(gridView返利单.GetRowCellValue(i, gridColFLD_iID)); model.FLD_cCode = gridView返利单.GetRowCellValue(i, gridColcCode).ToString().Trim(); model.FLD_Money = model.dMoney_kh; BaseFunction.ReturnDecimal(gridView返利单.GetRowCellValue(i, gridCol返利金额)); model.createUid = sUserID; model.dtmCreate = DateTime.Now; model.GUID = sGuid; model.DLS = gridView返利单.GetRowCellValue(i, gridCol代理商编码).ToString().Trim(); model.Remark = txt备注.Text.Trim(); DAL._高开返利核销单_SZ dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利核销单_SZ(); sSQL = dal.Add(model); iCou += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (sErr.Length > 0) { throw new Exception(sErr); } if (iCou > 0) { tran.Commit(); MessageBox.Show("保存成功\n单据号:" + sCode); txt单据号.Text = sCode; SetEnable(false); } else { throw new Exception("请选择需要保存的数据"); } } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "保存失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }