123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal
- {
- public class ReportMstDal
- {
- private IDatabase CurrDb = null;
- public ReportMstDal(IDatabase db)
- {
- CurrDb = db;
- }
- public ReportMst IUReportMst(ReportMst mst,string usercode, ref string errorinfo)
- {
- try
- {
- int result = 0;
- int id = mst.ID;
- if(mst.EntityStatusID==1)
- {
- string code = GetReportMstCode(ref errorinfo);
- if (code == "")
- {
- return null;
- }
- mst.FCode = code;
- mst.RecCode = usercode;
- mst.RecTime = DateTime.Now;
- mst.ModCode = usercode;
- mst.ModTime = DateTime.Now;
- result = CurrDb.InsertFor(mst, usercode);
- if(result<0)
- {
- return null;
- }
- object objid = CurrDb.FindObject("select @@IDENTITY");
- if (objid.ToString() == "")
- {
- return null;
- }
- id = int.Parse(objid.ToString());
- }
- else
- {
- mst.ModCode = usercode;
- mst.ModTime = DateTime.Now;
- result = CurrDb.UpdateFor(mst, usercode);
- if (result < 0)
- {
- return null;
- }
- }
- mst = CurrDb.FindEntityFor<ReportMst>(id);
- return mst;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- private string GetReportMstCode(ref string errorinfo)
- {
- try
- {
- StringBuilder sqlstr = new StringBuilder(100);
- string code = "R";
- sqlstr.AppendFormat("SELECT max(fcode) FROM ReportMst where fcode like '{0}%'", code);
- object obj = CurrDb.FindObject(sqlstr.ToString());
- if (obj.ToString() == "")
- return code + "00001";
- int fnum = int.Parse(obj.ToString().Substring(1, 5));
- fnum++;
- return code + fnum.ToString().PadLeft(5, '0');
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return "";
- }
- }
- //删除报告
- public int DelReportMst(ReportMst datarow, ref string errorinfo)
- {
- try
- {
- StringBuilder sqlstr = new StringBuilder(100);
- //删除oab记录
- //sqlstr.AppendFormat("delete from oab where ab00 in (select b.uid from (select id uid from oaa where oa00={0}) as b)", datarow["id"].ToString());
- sqlstr.AppendFormat("delete from ReportDetail where preid={0}", datarow.ID);
- int result = CurrDb.ExecuteBySql(sqlstr.ToString());
- if (result < 0)
- {
- return -1;
- }
- sqlstr.Clear();
- sqlstr.AppendFormat("delete from ReportMst where id={0}", datarow.ID);
- result = CurrDb
- .ExecuteBySql(sqlstr.ToString());
- if (result < 0)
- {
- return -1;
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- //删除报告
- public int DelReportMst(List<ReportMst> dt, ref string errorinfo)
- {
- try
- {
- int result = 0;
- foreach (var temprow in dt)
- {
- result = DelReportMst(temprow, ref errorinfo);
- if (result < 0)
- {
- return -1;
- }
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public ReportMst IUReportMst(ReportMst mst,List<ReportDetail> details,string usercode, ref string errorinfo)
- {
- try
- {
- ReportMst remst = IUReportMst(mst,usercode, ref errorinfo);
- if (remst==null)
- {
- return null;
- }
- //添加指令明细
- int result = IUReportDetail(details, remst.ID,usercode, ref errorinfo);
- if (result < 0)
- {
- return null;
- }
- return remst;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- //新增、修改、删除指令信息oaa
- private int IUReportDetail(List<ReportDetail> detaildt, int preid,string usercode, ref string errorinfo)
- {
- try
- {
- StringBuilder sqlstr = new StringBuilder(100);
- int result = 0;
- //删除
- List<ReportDetail> temprows = detaildt.Where(t => t.EntityStatusID < 0).ToList();
- foreach (var temprow in temprows)
- {
- sqlstr.Clear();
- sqlstr.AppendFormat("delete from ReportDetail where id={0}", temprow.ID);
- result = CurrDb.ExecuteBySql(sqlstr.ToString());
- if (result < 0)
- return -1;
- }
- //修改,可以批量
- temprows = detaildt.Where(t => t.EntityStatusID ==2).ToList();
- foreach(var item in temprows)
- {
- item.ModCode = usercode;
- item.ModTime = DateTime.Now;
- }
- result = CurrDb.UpdateFor<ReportDetail>(temprows, usercode);
- if (result < 0)
- {
- return -1;
- }
- temprows = detaildt.Where(t => t.EntityStatusID ==1).ToList();
- foreach (var item in temprows)
- {
- item.PreID = preid;
- item.RecCode = usercode;
- item.RecTime = DateTime.Now;
- item.ModCode = usercode;
- item.ModTime = DateTime.Now;
- }
- result = CurrDb.InsertFor<ReportDetail>(temprows, usercode);
- if (result < 0)
- {
- return -1;
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- //复制整个指令文件
- public ReportMst CopyReportMst( ReportMst datarow,string usercode, ref string errorinfo)
- {
- string sqlstr = "";
- List<ReportDetail> details = CurrDb.FindListForCondition<ReportDetail>(sqlstr, ref errorinfo).ToList();
- foreach(var item in details)
- {
- item.ID = 0;
- item.PreID = 0;
- item.EntityStatusID = 1;
- }
- ReportMst mst = new ReportMst();
- EntityHelper.CopyPropertyValue(datarow, mst);
- mst.EntityStatusID = 1;
- mst.ID = 0;
- ReportMst reentity= IUReportMst(mst,details,usercode, ref errorinfo);
- if (reentity==null)
- {
- return null;
- }
- return reentity;
- }
-
- }
- }
|