Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._回款_sap model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.收款单号 != null)
            {
                strSql1.Append("收款单号,");
                strSql2.Append("'" + model.收款单号 + "',");
            }
            if (model.收款单日期 != null)
            {
                strSql1.Append("收款单日期,");
                strSql2.Append("'" + model.收款单日期 + "',");
            }
            if (model.收款单金额 != null)
            {
                strSql1.Append("收款单金额,");
                strSql2.Append("" + model.收款单金额 + ",");
            }
            if (model.业务员编码 != null)
            {
                strSql1.Append("业务员编码,");
                strSql2.Append("'" + model.业务员编码 + "',");
            }
            if (model.业务员 != null)
            {
                strSql1.Append("业务员,");
                strSql2.Append("'" + model.业务员 + "',");
            }
            if (model.核销金额 != null)
            {
                strSql1.Append("核销金额,");
                strSql2.Append("" + model.核销金额 + ",");
            }
            if (model.核销日期 != null)
            {
                strSql1.Append("核销日期,");
                strSql2.Append("'" + model.核销日期 + "',");
            }
            if (model.发票号码 != null)
            {
                strSql1.Append("发票号码,");
                strSql2.Append("'" + model.发票号码 + "',");
            }
            if (model.发票日期 != null)
            {
                strSql1.Append("发票日期,");
                strSql2.Append("'" + model.发票日期 + "',");
            }
            if (model.销售组织 != null)
            {
                strSql1.Append("销售组织,");
                strSql2.Append("'" + model.销售组织 + "',");
            }
            if (model.客户编码 != null)
            {
                strSql1.Append("客户编码,");
                strSql2.Append("'" + model.客户编码 + "',");
            }
            if (model.客户名称 != null)
            {
                strSql1.Append("客户名称,");
                strSql2.Append("'" + model.客户名称 + "',");
            }
            if (model.发票金额 != null)
            {
                strSql1.Append("发票金额,");
                strSql2.Append("" + model.发票金额 + ",");
            }
            if (model.货币单位 != null)
            {
                strSql1.Append("货币单位,");
                strSql2.Append("'" + model.货币单位 + "',");
            }
            if (model.分配 != null)
            {
                strSql1.Append("分配,");
                strSql2.Append("'" + model.分配 + "',");
            }
            if (model.金税发票号 != null)
            {
                strSql1.Append("金税发票号,");
                strSql2.Append("'" + model.金税发票号 + "',");
            }
            if (model.清帐凭证号 != null)
            {
                strSql1.Append("清帐凭证号,");
                strSql2.Append("'" + model.清帐凭证号 + "',");
            }
            strSql.Append("insert into _回款_sap(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            return(strSql.ToString());
        }
Ejemplo n.º 3
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 = "";
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        sSQL = @"
select count(1) as iCou from [_回款_sap] where [收款单号] = '{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)
                        {
                            sSQL = @"
delete  [_回款_sap] where 收款单号 = '{0}'
";
                            sSQL = string.Format(sSQL, gridView1.GetRowCellValue(i, gridCol_收款单号).ToString().Trim());
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        Model._回款_sap mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._回款_sap();

                        mod.收款单号  = gridView1.GetRowCellDisplayText(i, gridCol_收款单号).ToString().Trim();
                        mod.收款单日期 = BaseFunction.ReturnDate(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.核销金额  = BaseFunction.ReturnDecimal(gridView1.GetRowCellDisplayText(i, gridCol_核销金额).ToString().Trim());
                        mod.核销日期  = BaseFunction.ReturnDate(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.发票金额  = 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.清帐凭证号 = gridView1.GetRowCellDisplayText(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("导入回款成功");

                        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();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._回款_sap model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update _回款_sap set ");
            if (model.收款单号 != null)
            {
                strSql.Append("收款单号='" + model.收款单号 + "',");
            }
            else
            {
                strSql.Append("收款单号= null ,");
            }
            if (model.收款单日期 != null)
            {
                strSql.Append("收款单日期='" + model.收款单日期 + "',");
            }
            else
            {
                strSql.Append("收款单日期= null ,");
            }
            if (model.收款单金额 != null)
            {
                strSql.Append("收款单金额=" + model.收款单金额 + ",");
            }
            else
            {
                strSql.Append("收款单金额= null ,");
            }
            if (model.业务员编码 != null)
            {
                strSql.Append("业务员编码='" + model.业务员编码 + "',");
            }
            else
            {
                strSql.Append("业务员编码= null ,");
            }
            if (model.业务员 != null)
            {
                strSql.Append("业务员='" + model.业务员 + "',");
            }
            else
            {
                strSql.Append("业务员= null ,");
            }
            if (model.核销金额 != null)
            {
                strSql.Append("核销金额=" + model.核销金额 + ",");
            }
            else
            {
                strSql.Append("核销金额= null ,");
            }
            if (model.核销日期 != null)
            {
                strSql.Append("核销日期='" + model.核销日期 + "',");
            }
            else
            {
                strSql.Append("核销日期= null ,");
            }
            if (model.发票号码 != null)
            {
                strSql.Append("发票号码='" + model.发票号码 + "',");
            }
            else
            {
                strSql.Append("发票号码= null ,");
            }
            if (model.发票日期 != null)
            {
                strSql.Append("发票日期='" + model.发票日期 + "',");
            }
            else
            {
                strSql.Append("发票日期= null ,");
            }
            if (model.销售组织 != null)
            {
                strSql.Append("销售组织='" + model.销售组织 + "',");
            }
            else
            {
                strSql.Append("销售组织= null ,");
            }
            if (model.客户编码 != null)
            {
                strSql.Append("客户编码='" + model.客户编码 + "',");
            }
            else
            {
                strSql.Append("客户编码= null ,");
            }
            if (model.客户名称 != null)
            {
                strSql.Append("客户名称='" + model.客户名称 + "',");
            }
            else
            {
                strSql.Append("客户名称= null ,");
            }
            if (model.发票金额 != null)
            {
                strSql.Append("发票金额=" + model.发票金额 + ",");
            }
            else
            {
                strSql.Append("发票金额= null ,");
            }
            if (model.货币单位 != null)
            {
                strSql.Append("货币单位='" + model.货币单位 + "',");
            }
            else
            {
                strSql.Append("货币单位= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where iID=" + model.iID + "");
            return(strSql.ToString());
        }