Пример #1
0
        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].[_高开返利核销单] 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._高开返利核销单 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利核销单();
                    sSQL = dal.Delete(txt单据号.Text.Trim());
                    iCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    tran.Commit();

                    if (iCou > 0)
                    {
                        MessageBox.Show("删除成功");

                        this.Close();
                    }
                }
                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();
            }
        }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView返利单.FocusedRowHandle -= 1;
                    gridView返利单.FocusedRowHandle += 1;
                }
                catch { }

                decimal d发票核销 = 0;
                for (int i = 0; i < gridView_发票.RowCount; i++)
                {
                    d发票核销 = d发票核销 + BaseFunction.ReturnDecimal(gridView_发票.GetRowCellValue(i, gridCol_HXMoney));
                }

                decimal d返利单核销 = 0;
                for (int i = 0; i < gridView返利单.RowCount; i++)
                {
                    d返利单核销 = d返利单核销 + BaseFunction.ReturnDecimal(gridView返利单.GetRowCellValue(i, gridColHXMoney));
                }
                if (d发票核销 != d返利单核销)
                {
                    throw new Exception("核销金额不正确");
                }


                int    iCou    = 0;
                string sErr返利单 = "";
                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].[_高开返利核销单] 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 [_高开返利核销单] where cCode = '{0}' 
";
                            sSQL = string.Format(sSQL, txt单据号.Text.Trim());
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    sSQL = @"
select max(cCode) as cCodeMax from [dbo].[_高开返利核销单] 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++)
                    {
                        decimal dUnMoney = BaseFunction.ReturnDecimal(gridView返利单.GetRowCellValue(i, gridColUnMoney));
                        decimal dHXMoney = BaseFunction.ReturnDecimal(gridView返利单.GetRowCellValue(i, gridColHXMoney));

                        if (dHXMoney == 0)
                        {
                            continue;
                        }

                        if (dHXMoney > dUnMoney)
                        {
                            sErr返利单 = sErr返利单 + "行" + (i + 1).ToString() + " 核销金额超额\n";
                            continue;
                        }

                        Model._高开返利核销单 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利核销单();
                        model.cCode     = sCode;
                        model.dtmDate   = DateTime.Today;
                        model.dMoney    = BaseFunction.ReturnDecimal(gridView返利单.GetRowCellValue(i, gridColHXMoney));
                        model.FLD_iID   = BaseFunction.ReturnLong(gridView返利单.GetRowCellValue(i, gridColFLD_iID));
                        model.FLD_cCode = gridView返利单.GetRowCellValue(i, gridColcCode).ToString().Trim();
                        model.FLD_Money = model.dMoney;
                        model.createUid = sUserID;
                        model.dtmCreate = DateTime.Now;
                        model.GUID      = sGuid;
                        model.DLS       = gridView返利单.GetRowCellValue(i, gridCol代理商编码).ToString().Trim();
                        model.Remark    = txt备注.Text.Trim();

                        DAL._高开返利核销单 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利核销单();
                        sSQL  = dal.Add(model);
                        iCou += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    for (int i = 0; i < gridView_发票.RowCount; i++)
                    {
                        decimal dUnMoney = BaseFunction.ReturnDecimal(gridView_发票.GetRowCellValue(i, gridCol_UnMoney));
                        decimal dHXMoney = BaseFunction.ReturnDecimal(gridView_发票.GetRowCellValue(i, gridCol_HXMoney));

                        if (dHXMoney == 0)
                        {
                            continue;
                        }

                        if (dHXMoney > dUnMoney)
                        {
                            sErr发票 = sErr发票 + "行" + (i + 1).ToString() + " 核销金额超额\n";
                            continue;
                        }

                        Model._高开返利核销单 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利核销单();

                        model.cCode     = sCode;
                        model.dtmDate   = DateTime.Today;
                        model.dMoney    = BaseFunction.ReturnDecimal(gridView_发票.GetRowCellValue(i, gridCol_HXMoney));
                        model.FP_IDs    = BaseFunction.ReturnLong(gridView_发票.GetRowCellValue(i, gridCol_FP_IDs));
                        model.FP_Code   = gridView_发票.GetRowCellValue(i, gridCol_FPCode).ToString().Trim();
                        model.FP_Money  = model.dMoney;
                        model.createUid = sUserID;
                        model.dtmCreate = DateTime.Now;
                        model.GUID      = sGuid;
                        model.DLS       = gridView_发票.GetRowCellValue(i, gridCol_代理商编码).ToString().Trim();
                        model.Remark    = txt备注.Text.Trim();

                        DAL._高开返利核销单 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利核销单();
                        sSQL  = dal.Add(model);
                        iCou += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    string sErr = "";
                    if (sErr发票.Length > 0)
                    {
                        sErr = sErr + "发票:\n" + sErr发票;
                    }
                    if (sErr返利单.Length > 0)
                    {
                        sErr = sErr + "返利单:\n" + sErr返利单;
                    }

                    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();
            }
        }