123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Models;
- using System.Data.SqlClient;
- using System.Data;
- namespace DAL
- {
- /// <summary>
- /// 对外收款账单数据访问类
- /// </summary>
- public class ForeignReceivablesService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<ForeignReceivables> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<ForeignReceivables>.excuteSql(new ForeignReceivables(), "ForeignReceivables", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- ForeignReceivables excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<ForeignReceivables> ioaList = excuteSql(sql, param);
- //判断集合是否为空
- if (ioaList == null || ioaList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return ioaList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public ForeignReceivables GetForeignReceivablesByDIId(int DIId)
- {
- //调用获取单个对象的方法
- return excuteType("select * from ForeignReceivables where DIId = @DIId and isdel = 0", new SqlParameter("@DIId", DIId));
- }
- /// <summary>
- /// 根据编号和添加模块 查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public ForeignReceivables GetForeignReceivablesByDIId(int DIId,int AddingWay)
- {
- //调用获取单个对象的方法
- return excuteType("select * from ForeignReceivables where DIId = @DIId and AddingWay = @AddingWay and isdel = 0", new SqlParameter("@DIId", DIId), new SqlParameter("@AddingWay", AddingWay));
- }
- /// <summary>
- /// 根据编号查询对象信息 - 集合
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者对象集合信息</returns>
- public List<ForeignReceivables> GetAllByDIId(int DIId)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from ForeignReceivables where DIId = @DIId", new SqlParameter("@DIId", DIId));
- }
- /// <summary>
- /// 批量添加方法
- /// </summary>
- /// <param name="list"></param>
- /// <returns></returns>
- public bool AddUpCardAuditContent(List<ForeignReceivables> list)
- {
- SqlCommand cmd = SqlHelper.createCon().CreateCommand();
- cmd.Connection.Open();
- //SqlTransaction trans = cmd.Connection.BeginTransaction();
-
- try
- {
- foreach (ForeignReceivables fr in list)
- {
- cmd.CommandText = "insert into ForeignReceivables values("+fr.Id+"," + fr.DIId + ",'" + fr.PriceName + "'," + fr.Price + "," + fr.Count + ",'" + fr.Unit + "'," + fr.ItemSumPrice + ",'" + fr.To + "','" + fr.ToTel + "','" + fr.PayDate + "','" + fr.Attention + "'," + fr.Operators + ",'" + fr.OperatorsDate + "'," + fr.IsDel +","+fr.Rate+",'"+fr.Currency+ "','" + fr.AddingWay + "')";
- cmd.ExecuteNonQuery();
- }
- //trans.Commit();
- cmd.Connection.Close();
- return true;
- }
- catch
- {
- //trans.Rollback();
- cmd.Connection.Close();
- return false;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelForeignReceivables(int DIId)
- {
- if (SqlHelper.ExecuteNonQuery("delete ForeignReceivables where DIId = @DIId", CommandType.Text, new SqlParameter("@DIId", DIId)) > 0)
- return true;
- return false;
- }
- public float GetSumForForeignReceivables(int diid)
- {
- object o=SqlHelper.ExecuteScalar("select sum(ItemSumPrice) from ForeignReceivables where isdel = 0 and diid="+diid,CommandType.Text,null);
- if (o != null && o.ToString()!="")
- return float.Parse(o.ToString());
- else
- return 0;
- }
- /// <summary>
- /// 获取所有收款信息(应收、已收)
- /// </summary>
- /// <param name="p"></param>
- /// <returns></returns>
- public DataTable getAllForReceivables(int diid)
- {
- DataTable dt = SqlHelper.TransferProcedure("[dbo].[exec_ReceviedAccount]", CommandType.StoredProcedure, new SqlParameter("@diid", diid));
- if (dt != null)
- return dt;
- return null;
- }
- /// <summary>
- /// 查询应收款项最大id
- /// </summary>
- /// <returns></returns>
- public int GetMaxID()
- {
- object result = SqlHelper.ExecuteScalar("select max(id) from ForeignReceivables", CommandType.Text, null);
- if (result != null)
- return Convert.ToInt32(result);
- else
- return 0;
- }
- }
- }
|