Exemple #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    int    iCou = 0;
                    string sErr = "";
                    string sSQL = "";

                    string sString = "";

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridCol选择));
                        if (!b)
                        {
                            continue;
                        }

                        sSQL = @"
select count(1) as iCou from [dbo].[_高开返利单_SZ] where cSBVCode = '{0}'
                        ";
                        sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
                        long l = BaseFunction.ReturnLong(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                        if (l > 0)
                        {
                            sString = sString + "行 " + (i + 1).ToString() + "已经做了高开返利单\n";
                            gridView1.SetRowCellValue(i, gridCol选择, false);
                            continue;
                        }

                        //未做高开返利单的当月发票全部删除
                        sSQL = @"
delete 
from [dbo].[_发票_sap] 
where year([发票日期]) = {0} and month([发票日期]) = {1}
	and 发票号码 not in (
			select DISTINCT 发票号码 from [_发票_sap] where year([发票日期]) = {0} and month([发票日期]) = {1} and iID in (select FPIDs from [dbo].[_高开返利单_SZ])
			)
";
                        sSQL = string.Format(sSQL, BaseFunction.ReturnInt(lookUpEditYear.EditValue).ToString().Trim(), BaseFunction.ReturnInt(lookUpEditMonth.EditValue).ToString().Trim());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

//                        sSQL = @"
//select count(1) as iCou from [_发票_sap] where 发票号码 = '{0}'
//                        ";
//                        sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
//                        l = BaseFunction.ReturnLong(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);

//                        if (l > 0)
//                        {
//                            sSQL = @"
//delete  [_发票_sap] where 发票号码 = '{0}'
//                        ";
//                            sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
//                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
//                        }
                    }

                    if (sString.Length > 0)
                    {
                        FrmMsgBox frm = new FrmMsgBox();
                        frm.Text = "存在已经做了高开返利单,是否继续?";
                        frm.richTextBox1.Text = sString;

                        frm.ShowDialog();


                        if (DialogResult.OK != frm.DialogResult)
                        {
                            throw new Exception("用户取消操作!");
                        }
                    }

                    try
                    {
                        gridView1.FocusedRowHandle -= 1;
                        gridView1.FocusedRowHandle += 1;
                    }
                    catch { }


                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool b = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridCol选择));
                        if (!b)
                        {
                            continue;
                        }

//                        sSQL = @"
//select count(1) as iCou from [dbo].[_高开返利单_SZ] where cSBVCode = '{0}'
//                        ";
//                        sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
//                        long l = BaseFunction.ReturnLong(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
//                        if (l > 0)
//                        {
//                            sString = sString + "行 " + (i + 1).ToString() + "已经做了高开返利单";
//                            continue;
//                        }


//                        sSQL = @"
//select count(1) as iCou from [_发票_sap] where 发票号码 = '{0}'
//                        ";
//                        sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
//                        l = BaseFunction.ReturnLong(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);

//                        if (l > 0)
//                        {
//                            sSQL = @"
//delete  [_发票_sap] where 发票号码 = '{0}'
//                        ";
//                            sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
//                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
//                        }

                        Model._发票_sap mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._发票_sap();
                        mod.销售组织   = gridView1.GetRowCellDisplayText(i, gridCol销售组织).ToString().Trim();
                        mod.发票号码   = gridView1.GetRowCellDisplayText(i, gridCol发票号码).ToString().Trim();
                        mod.发票类型   = gridView1.GetRowCellDisplayText(i, gridCol发票类型).ToString().Trim();
                        mod.发票类型名称 = gridView1.GetRowCellDisplayText(i, gridCol发票类型名称).ToString().Trim();
                        mod.发票日期   = BaseFunction.ReturnDate(gridView1.GetRowCellDisplayText(i, gridCol发票日期).ToString().Trim());
                        mod.客户编码   = gridView1.GetRowCellDisplayText(i, gridCol客户编码).ToString().Trim();
                        mod.客户名称   = gridView1.GetRowCellDisplayText(i, gridCol客户名称).ToString().Trim();
                        mod.代理商编码  = gridView1.GetRowCellDisplayText(i, gridCol代理商编码).ToString().Trim();
                        mod.代理商名称  = gridView1.GetRowCellDisplayText(i, gridCol代理商名称).ToString().Trim();
                        mod.业务员编码  = gridView1.GetRowCellDisplayText(i, gridCol业务员编码).ToString().Trim();
                        mod.业务员名称  = gridView1.GetRowCellDisplayText(i, gridCol业务员名称).ToString().Trim();
                        mod.省份编码   = gridView1.GetRowCellDisplayText(i, gridCol省份编码).ToString().Trim();
                        mod.省份名称   = gridView1.GetRowCellDisplayText(i, gridCol省份名称).ToString().Trim();
                        mod.城市编码   = gridView1.GetRowCellDisplayText(i, gridCol城市编码).ToString().Trim();
                        mod.发货单号   = gridView1.GetRowCellDisplayText(i, gridCol发货单号).ToString().Trim();
                        mod.发货行号   = BaseFunction.ReturnInt(gridView1.GetRowCellDisplayText(i, gridCol发货行号).ToString().Trim());
                        mod.货物编码   = gridView1.GetRowCellDisplayText(i, gridCol货物编码).ToString().Trim();
                        mod.货物旧编码  = gridView1.GetRowCellDisplayText(i, gridCol货物旧编码).ToString().Trim();
                        mod.货物名称   = gridView1.GetRowCellDisplayText(i, gridCol货物名称).ToString().Trim();
                        mod.规格型号   = gridView1.GetRowCellDisplayText(i, gridCol规格型号).ToString().Trim();
                        mod.批次     = gridView1.GetRowCellDisplayText(i, gridCol批次).ToString().Trim();
                        mod.单价     = BaseFunction.ReturnDecimal(gridView1.GetRowCellDisplayText(i, gridCol单价).ToString().Trim());
                        mod.开票数量   = BaseFunction.ReturnDecimal(gridView1.GetRowCellDisplayText(i, gridCol开票数量).ToString().Trim());
                        mod.金额     = BaseFunction.ReturnDecimal(gridView1.GetRowCellDisplayText(i, gridCol金额).ToString().Trim());
                        mod.货币单位   = gridView1.GetRowCellDisplayText(i, gridCol货币单位).ToString().Trim();
                        mod.发票已取消  = gridView1.GetRowCellDisplayText(i, gridCol发票已取消).ToString().Trim();
                        mod.被冲销的号码 = gridView1.GetRowCellDisplayText(i, gridCol被冲销的号码).ToString().Trim();
                        mod.PO项目   = gridView1.GetRowCellDisplayText(i, gridColPO项目).ToString().Trim();
                        mod.iID    = BaseFunction.ReturnLong(gridView1.GetRowCellDisplayText(i, gridColiID));
                        mod.金税发票号码 = gridView1.GetRowCellDisplayText(i, gridCol金税发票号码).ToString().Trim();

                        DAL._发票_sap dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._发票_sap();


                        if (b编辑 && mod.iID > 0)
                        {
                            sSQL = dal.Update(mod);
                        }
                        else
                        {
                            sSQL = dal.Add(mod);
                        }
                        iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr.Trim());
                    }

                    b编辑 = false;

                    if (iCou > 0)
                    {
                        tran.Commit();

                        MessageBox.Show("导入发票成功");

                        gridControl1.DataSource = null;
                    }
                    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();
            }
        }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView回款.FocusedRowHandle -= 1;
                    gridView回款.FocusedRowHandle += 1;

                    gridView发票.FocusedRowHandle -= 1;
                    gridView发票.FocusedRowHandle += 1;
                }
                catch { }


                if (radio发票.Checked)
                {
                    SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                    conn.Open();
                    //启用事务
                    SqlTransaction tran = conn.BeginTransaction();
                    try
                    {
                        int    iCou = 0;
                        string sErr = "";
                        string sSQL = "";

                        for (int i = 0; i < gridView发票.RowCount; i++)
                        {
                            sSQL = @"
select count(1) as iCou from [dbo].[_高开返利单] where cSBVCode = '{0}'
";
                            sSQL = string.Format(sSQL, gridView发票.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
                            long l = BaseFunction.ReturnLong(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                            if (l > 0)
                            {
                                sErr = sErr + "行 " + (i + 1).ToString() + "已经做了高开返利单";
                                continue;
                            }

                            sSQL = @"
select count(1) as iCou from [_发票_sap] where 发票号码 = '{0}'
";
                            sSQL = string.Format(sSQL, gridView发票.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
                            l    = BaseFunction.ReturnLong(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);

                            if (l > 0)
                            {
                                sSQL = @"
delete  [_发票_sap] where 发票号码 = '{0}'
";
                                sSQL = string.Format(sSQL, gridView发票.GetRowCellValue(i, gridCol发票号码).ToString().Trim());
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                        }

                        for (int i = 0; i < gridView发票.RowCount; i++)
                        {
                            Model._发票_sap mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._发票_sap();
                            mod.销售组织   = gridView发票.GetRowCellValue(i, gridCol销售组织).ToString().Trim();
                            mod.发票号码   = gridView发票.GetRowCellValue(i, gridCol发票号码).ToString().Trim();
                            mod.发票类型   = gridView发票.GetRowCellValue(i, gridCol发票类型).ToString().Trim();
                            mod.发票类型名称 = gridView发票.GetRowCellValue(i, gridCol发票类型名称).ToString().Trim();
                            mod.发票日期   = BaseFunction.ReturnDate(gridView发票.GetRowCellValue(i, gridCol发票日期).ToString().Trim());
                            mod.客户编码   = gridView发票.GetRowCellValue(i, gridCol客户编码).ToString().Trim();
                            mod.客户名称   = gridView发票.GetRowCellValue(i, gridCol客户名称).ToString().Trim();
                            mod.代码商编码  = gridView发票.GetRowCellValue(i, gridCol代码商编码).ToString().Trim();
                            mod.代理商名称  = gridView发票.GetRowCellValue(i, gridCol代理商名称).ToString().Trim();
                            mod.业务员编码  = gridView发票.GetRowCellValue(i, gridCol业务员编码).ToString().Trim();
                            mod.业务员名称  = gridView发票.GetRowCellValue(i, gridCol业务员名称).ToString().Trim();
                            mod.省份编码   = gridView发票.GetRowCellValue(i, gridCol省份编码).ToString().Trim();
                            mod.省份名称   = gridView发票.GetRowCellValue(i, gridCol省份名称).ToString().Trim();
                            mod.城市编码   = gridView发票.GetRowCellValue(i, gridCol城市编码).ToString().Trim();
                            mod.发货单号   = gridView发票.GetRowCellValue(i, gridCol发货单号).ToString().Trim();
                            mod.发货行号   = BaseFunction.ReturnInt(gridView发票.GetRowCellValue(i, gridCol发货行号).ToString().Trim());
                            mod.货物编码   = gridView发票.GetRowCellValue(i, gridCol货物编码).ToString().Trim();
                            mod.货物名称   = gridView发票.GetRowCellValue(i, gridCol货物名称).ToString().Trim();
                            mod.规格型号   = gridView发票.GetRowCellValue(i, gridCol规格型号).ToString().Trim();
                            mod.批次     = gridView发票.GetRowCellValue(i, gridCol批次).ToString().Trim();
                            mod.单价     = BaseFunction.ReturnDecimal(gridView发票.GetRowCellValue(i, gridCol单价).ToString().Trim());
                            mod.开票数量   = BaseFunction.ReturnDecimal(gridView发票.GetRowCellValue(i, gridCol开票数量).ToString().Trim());
                            mod.金额     = BaseFunction.ReturnDecimal(gridView发票.GetRowCellValue(i, gridCol金额).ToString().Trim());
                            mod.货币单位   = gridView发票.GetRowCellValue(i, gridCol货币单位).ToString().Trim();

                            DAL._发票_sap dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._发票_sap();
                            sSQL = dal.Add(mod);
                            iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }

                        if (sErr.Length > 0)
                        {
                            throw new Exception(sErr.Trim());
                        }

                        if (iCou > 0)
                        {
                            tran.Commit();

                            MessageBox.Show("导入发票成功");

                            gridControl发票.DataSource = null;
                        }
                        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();
            }

            if (radio回款.Checked)
            {
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    int    iCou = 0;
                    string sErr = "";

                    string sSQL = "";
                    for (int i = 0; i < gridView回款.RowCount; i++)
                    {
                        sSQL = @"
select count(1) as iCou from [_回款_sap] where [收款单号] = '{0}'
";
                        sSQL = string.Format(sSQL, gridView回款.GetRowCellValue(i, gridCol_收款单号).ToString().Trim());
                        long l = BaseFunction.ReturnLong(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);

                        if (l > 0)
                        {
                            sSQL = @"
delete  [_回款_sap] where 收款单号 = '{0}'
";
                            sSQL = string.Format(sSQL, gridView回款.GetRowCellValue(i, gridCol_收款单号).ToString().Trim());
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }
                    for (int i = 0; i < gridView回款.RowCount; i++)
                    {
                        Model._回款_sap mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._回款_sap();

                        mod.收款单号  = gridView回款.GetRowCellValue(i, gridCol_收款单号).ToString().Trim();
                        mod.收款单日期 = BaseFunction.ReturnDate(gridView回款.GetRowCellValue(i, gridCol_收款单日期).ToString().Trim());
                        mod.收款单金额 = BaseFunction.ReturnDecimal(gridView回款.GetRowCellValue(i, gridCol_收款单金额).ToString().Trim());
                        mod.业务员编码 = gridView回款.GetRowCellValue(i, gridCol_业务员编码).ToString().Trim();
                        mod.业务员   = gridView回款.GetRowCellValue(i, gridCol_业务员).ToString().Trim();
                        mod.核销金额  = BaseFunction.ReturnDecimal(gridView回款.GetRowCellValue(i, gridCol_核销金额).ToString().Trim());
                        mod.核销日期  = BaseFunction.ReturnDate(gridView回款.GetRowCellValue(i, gridCol_核销日期).ToString().Trim());
                        mod.发票号码  = gridView回款.GetRowCellValue(i, gridCol_发票号码).ToString().Trim();
                        mod.发票日期  = BaseFunction.ReturnDate(gridView回款.GetRowCellValue(i, gridCol_发票日期).ToString().Trim());
                        mod.销售组织  = gridView回款.GetRowCellValue(i, gridCol_销售组织).ToString().Trim();
                        mod.客户编码  = gridView回款.GetRowCellValue(i, gridCol_客户编码).ToString().Trim();
                        mod.客户名称  = gridView回款.GetRowCellValue(i, gridCol客户名称).ToString().Trim();
                        mod.发票金额  = BaseFunction.ReturnDecimal(gridView回款.GetRowCellValue(i, gridCol_发票金额).ToString().Trim());
                        mod.货币单位  = gridView回款.GetRowCellValue(i, gridCol_货币单位).ToString().Trim();

                        DAL._回款_sap dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._回款_sap();
                        sSQL = dal.Add(mod);

                        iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr.Trim());
                    }

                    if (iCou > 0)
                    {
                        tran.Commit();

                        MessageBox.Show("导入回款成功");

                        gridControl回款.DataSource = null;
                    }
                    else
                    {
                        throw new Exception("请选择需要保存的数据");
                    }
                }

                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
        }