public override bool DoSave() { //if (!this.ControlManager.CheckControlValue()) //{ // return false; //} this.ValidateChildren(); if (!this.ControlManager.SaveCurrent()) { return(false); } 凭证 pz = this.ControlManager.DisplayManager.CurrentItem as 凭证; pz.操作人 = "出纳"; using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Hd.Model.凭证>()) { try { rep.BeginTransaction(); decimal sum = 0; pz.凭证费用明细 = new List <凭证费用明细>(); foreach (Xceed.Grid.DataRow row in grdFymx.DataRows) { decimal je = Feng.Utils.ConvertHelper.ToDecimal(row.Cells["金额"].Value).Value; sum += je; 凭证费用明细 pzfymx = new 凭证费用明细(); pzfymx.备注 = (string)row.Cells["备注"].Value; pzfymx.金额 = je; pzfymx.凭证 = pz; pzfymx.凭证费用类别编号 = (int?)用途分类.SelectedDataValue; pzfymx.收付标志 = 收付标志.收; pzfymx.相关人编号 = (string)付款对象.SelectedDataValue; pzfymx.业务类型编号 = (int?)业务分类.SelectedDataValue; pzfymx.费用项编号 = (string)row.Cells["费用项"].Value; pzfymx.费用 = new List <费用>(); int ytfl = (int)用途分类.SelectedDataValue; if (ytfl == 101) // 业务应付 { pzfymx.费用项编号 = (string)row.Cells["费用项"].Value; } else if (ytfl == 103) //其他应付 { pzfymx.费用项编号 = "002"; } else if (ytfl == 203 || ytfl == 204 || ytfl == 205) // 借款套现押金 { pzfymx.费用项编号 = "012"; } else { pzfymx.费用项编号 = (string)row.Cells["费用项"].Value; } pz.凭证费用明细.Add(pzfymx); } pz.出纳编号 = SystemConfiguration.UserName; pz.会计金额 = sum; pz.金额.币制编号 = "CNY"; pz.金额.数额 = pz.会计金额; pz.凭证类别 = 凭证类别.收款凭证; pz.相关人编号 = (string)付款对象.SelectedDataValue; pz.自动手工标志 = 自动手工标志.手工; (new 凭证Dao()).Save(rep, pz); foreach (凭证费用明细 pzfymx in pz.凭证费用明细) { (new HdBaseDao <凭证费用明细>()).Save(rep, pzfymx); } (new 凭证Dao()).Submit(rep, pz); rep.CommitTransaction(); if (this.ControlManager.ControlCheckExceptionProcess != null) { this.ControlManager.ControlCheckExceptionProcess.ClearAllError(); } this.ControlManager.State = StateType.View; this.ControlManager.OnCurrentItemChanged(); return(true); } catch (Exception ex) { rep.RollbackTransaction(); ServiceProvider.GetService <IExceptionProcess>().ProcessWithNotify(ex); return(false); } } }
public static void AddFees(凭证 master, IList <费用> list, IControlManager <凭证费用明细> detailCm, bool add, 收付标志?asDzd收付标志) { if (list == null) { return; } List <费用> newList = new List <费用>(); foreach (费用 i in list) { if (i.凭证费用明细 == null) { newList.Add(i); } } IList <凭证费用明细> ret = new List <凭证费用明细>(); if (!asDzd收付标志.HasValue) { // 费用实体类型. 收付标志, 费用项编号, 相关人编号 Dictionary <Tuple <int, 收付标志, string, string>, IList <费用> > dict = Cd.Model.Utility.GroupFyToPzYsyf(newList); foreach (KeyValuePair <Tuple <int, 收付标志, string, string>, IList <费用> > kvp in dict) { 凭证费用明细 pzs1 = new 凭证费用明细(); decimal sum = 0; foreach (费用 k4 in kvp.Value) { sum += k4.金额.Value; k4.凭证费用明细 = pzs1; } //string s = NameValueMappingCollection.Instance.FindNameFromId("信息_业务类型_全部", kvp.Key.Item1); //if (string.IsNullOrEmpty(s)) //{ // pzs1.业务类型编号 = null; //} //else //{ // pzs1.业务类型编号 = kvp.Key.Item1; //} pzs1.业务类型编号 = kvp.Key.Item1; pzs1.费用 = kvp.Value; pzs1.费用项编号 = kvp.Key.Item3; pzs1.金额 = sum; pzs1.收付标志 = kvp.Key.Item2; pzs1.相关人编号 = kvp.Key.Item4; // pzs1.凭证 = pz; ret.Add(pzs1); } } else { Dictionary <Tuple <int, string>, IList <费用> > dict = Cd.Model.Utility.GroupFyToDzdYsyf(newList); foreach (KeyValuePair <Tuple <int, string>, IList <费用> > kvp in dict) { 凭证费用明细 pzs1 = new 凭证费用明细(); decimal sum = 0; foreach (费用 k4 in kvp.Value) { if (k4.收付标志 == asDzd收付标志.Value) { sum += k4.金额.Value; } else { sum -= k4.金额.Value; } k4.凭证费用明细 = pzs1; } //string s = NameValueMappingCollection.Instance.FindNameFromId("信息_业务类型_全部", kvp.Key.First); //if (string.IsNullOrEmpty(s)) //{ // pzs1.业务类型编号 = null; //} //else //{ // pzs1.业务类型编号 = kvp.Key.First; //} pzs1.业务类型编号 = kvp.Key.Item1; pzs1.费用 = kvp.Value; pzs1.费用项编号 = "000"; // 常规应收应付 pzs1.金额 = sum; pzs1.收付标志 = asDzd收付标志.Value; pzs1.相关人编号 = kvp.Key.Item2; // pzs1.凭证 = pz; ret.Add(pzs1); } } if (add) { foreach (凭证费用明细 item in ret) { detailCm.AddNew(); detailCm.DisplayManager.Items[detailCm.DisplayManager.Position] = item; detailCm.EndEdit(); foreach (费用 i in item.费用) { i.凭证费用明细 = item; } } } else { if (ret.Count == 0) { return; } System.Diagnostics.Debug.Assert(ret.Count <= 1, "选出多个凭证费用明细,请查证!"); System.Diagnostics.Debug.Assert(ret[0].费用项编号 == detailCm.DisplayManagerT.CurrentEntity.费用项编号, "凭证费用明细费用项和选择的费用项不同!"); System.Diagnostics.Debug.Assert(ret[0].相关人编号 == detailCm.DisplayManagerT.CurrentEntity.相关人编号, "凭证费用明细费用项和选择的相关人不同!"); System.Diagnostics.Debug.Assert(ret[0].收付标志 == detailCm.DisplayManagerT.CurrentEntity.收付标志, "凭证费用明细费用项和选择的相关人不同!"); using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <费用>()) { rep.Initialize(detailCm.DisplayManagerT.CurrentEntity.费用, detailCm.DisplayManagerT.CurrentEntity); } if (detailCm.DisplayManagerT.CurrentEntity.费用 == null) { detailCm.DisplayManagerT.CurrentEntity.费用 = new List <费用>(); } foreach (费用 i in ret[0].费用) { i.凭证费用明细 = detailCm.DisplayManagerT.CurrentEntity; } detailCm.EditCurrent(); detailCm.EndEdit(); } }
public override bool DoSave() { //if (!this.ControlManager.CheckControlValue()) //{ // return false; //} this.ValidateChildren(); if (!this.ControlManager.SaveCurrent()) { return(false); } 凭证 pz = this.ControlManager.DisplayManager.CurrentItem as 凭证; pz.操作人 = "会计"; using (var rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Hd.Model.凭证>() as Feng.NH.INHibernateRepository) { try { rep.BeginTransaction(); decimal sum = 0; pz.凭证费用明细 = new List <凭证费用明细>(); foreach (Xceed.Grid.DataRow row in grdFymx.DataRows) { decimal je = Feng.Utils.ConvertHelper.ToDecimal(row.Cells["金额"].Value).Value; sum += je; 凭证费用明细 pzfymx = new 凭证费用明细(); pzfymx.备注 = (string)row.Cells["备注"].Value; pzfymx.金额 = je; pzfymx.凭证 = pz; pzfymx.凭证费用类别编号 = (int?)row.Cells["凭证费用类别"].Value; pzfymx.收付标志 = Hd.Model.收付标志.付; pzfymx.相关人编号 = (string)付款对象.SelectedDataValue; pzfymx.业务类型编号 = (int?)row.Cells["业务分类"].Value; pzfymx.费用项编号 = (string)row.Cells["费用项"].Value; pzfymx.费用 = new List <费用>(); pzfymx.结算期限 = (DateTime?)row.Cells["结算期限"].Value; 凭证用途分类 ytfl = (凭证用途分类)用途分类.SelectedDataValue; if (ytfl == 凭证用途分类.业务应付) // 业务应付 { pzfymx.业务类型编号 = (int?)业务分类.SelectedDataValue; } else if (ytfl == 凭证用途分类.其他应付) { pzfymx.业务类型编号 = 111; pzfymx.费用项编号 = "002"; } else if (ytfl == 凭证用途分类.其他报销) { pzfymx.费用项编号 = (string)row.Cells["费用项"].Value; } else if (ytfl == 凭证用途分类.业务报销) { 普通票 piao = null; 普通箱 xiang = null; piao = rep.UniqueResult <Hd.Model.普通票>(NHibernate.Criterion.DetachedCriteria.For <Hd.Model.普通票>() .Add(NHibernate.Criterion.Expression.Eq("货代自编号", row.Cells["自编号"].Value))); if (piao == null) { throw new InvalidUserOperationException("自编号" + (string)row.Cells["自编号"].Value + "输入有误,请重新输入!"); } switch (业务分类.SelectedDataValue.ToString()) { case "11": using (var rep2 = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Hd.Model.Jk.进口箱>() as Feng.NH.INHibernateRepository) { if (row.Cells["箱号"].Value != null) { xiang = rep2.UniqueResult <Hd.Model.Jk.进口箱>(NHibernate.Criterion.DetachedCriteria.For <Hd.Model.Jk.进口箱>() .Add(NHibernate.Criterion.Expression.Eq("箱号", row.Cells["箱号"].Value)) .CreateCriteria("票") .Add(NHibernate.Criterion.Expression.Eq("货代自编号", row.Cells["自编号"].Value))); if (xiang == null) { throw new InvalidUserOperationException("箱号" + (string)row.Cells["箱号"].Value + "输入有误,请重新输入!"); } } } break; case "15": using (var rep2 = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Hd.Model.Jk.进口箱>() as Feng.NH.INHibernateRepository) { //piao = rep2.Session.CreateCriteria<Hd.Model.普通票>() // .Add(NHibernate.Criterion.Expression.Eq("货代自编号", row.Cells["自编号"].Value)) // .UniqueResult<Hd.Model.普通票>(); //if (piao == null) //{ // throw new InvalidUserOperationException("自编号" + (string)row.Cells["自编号"].Value + "输入有误,请重新输入!"); //} if (row.Cells["箱号"].Value != null) { xiang = rep2.UniqueResult <Hd.Model.Nmcg.内贸出港箱>(NHibernate.Criterion.DetachedCriteria.For <Hd.Model.Nmcg.内贸出港箱>() .Add(NHibernate.Criterion.Expression.Eq("箱号", row.Cells["箱号"].Value)) .CreateCriteria("票") .Add(NHibernate.Criterion.Expression.Eq("货代自编号", row.Cells["自编号"].Value))); if (xiang == null) { throw new InvalidUserOperationException("箱号" + (string)row.Cells["箱号"].Value + "输入有误,请重新输入!"); } } } break; case "45": using (var rep2 = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <Hd.Model.Jk.进口票>() as Feng.NH.INHibernateRepository) { //piao = rep2.Session.CreateCriteria<Hd.Model.普通票>() // .Add(NHibernate.Criterion.Expression.Eq("货代自编号", row.Cells["自编号"].Value)) // .UniqueResult<Hd.Model.普通票>(); //if (piao == null) //{ // throw new InvalidUserOperationException("自编号" + (string)row.Cells["自编号"].Value + "输入有误,请重新输入!"); //} if (row.Cells["箱号"].Value != null) { xiang = rep2.UniqueResult <Hd.Model.Jk2.进口其他业务箱>(NHibernate.Criterion.DetachedCriteria.For <Hd.Model.Jk2.进口其他业务箱>() .Add(NHibernate.Criterion.Expression.Eq("箱号", row.Cells["箱号"].Value)) .CreateCriteria("票") .Add(NHibernate.Criterion.Expression.Eq("货代自编号", row.Cells["自编号"].Value))); if (xiang == null) { throw new InvalidUserOperationException("箱号" + (string)row.Cells["箱号"].Value + "输入有误,请重新输入!"); } } } break; default: throw new ArgumentException("不合理的业务类型分类!"); } NHibernate.Criterion.DetachedCriteria cri = NHibernate.Criterion.DetachedCriteria.For <业务费用>() .Add(NHibernate.Criterion.Expression.Eq("票.ID", piao.ID)) .Add(NHibernate.Criterion.Expression.Eq("费用项编号", row.Cells["费用项"].Value)) .Add(NHibernate.Criterion.Expression.Eq("收付标志", Hd.Model.收付标志.付)); if (xiang != null) { cri = cri.Add(NHibernate.Criterion.Expression.Eq("箱.ID", xiang.ID)); } else { cri = cri.Add(NHibernate.Criterion.Expression.IsNull("箱")); } IList <业务费用> list = rep.List <业务费用>(cri); cri = NHibernate.Criterion.DetachedCriteria.For <费用信息>() .Add(NHibernate.Criterion.Expression.Eq("票.ID", piao.ID)) .Add(NHibernate.Criterion.Expression.Eq("费用项编号", row.Cells["费用项"].Value)); IList <费用信息> fyxxs = rep.List <费用信息>(cri); if (fyxxs.Count > 0) { if (!fyxxs[0].完全标志付) { fyxxs[0].完全标志付 = true; (new HdBaseDao <费用信息>()).Update(rep, fyxxs[0]); } else { throw new InvalidUserOperationException("货代自编号" + piao.货代自编号 + "费用项" + row.Cells["费用项"].Value.ToString() + "已打完全标志,不能修改费用!"); } } bool exist = false; if (list.Count > 0) { foreach (业务费用 i in list) { if (i.金额 == je && i.相关人编号 == pzfymx.相关人编号 && i.凭证费用明细 == null) { i.凭证费用明细 = pzfymx; (new 业务费用Dao()).Update(rep, i); pzfymx.费用.Add(i); exist = true; break; } } } if (!exist) { if (list.Count > 1) { throw new InvalidUserOperationException("货代自编号" + piao.货代自编号 + "费用项" + row.Cells["费用项"].Value.ToString() + "已存在多条费用,且无费用金额一致,请先修改一致!"); } else if (list.Count == 0) { 业务费用 fy = new 业务费用(); fy.备注 = (string)row.Cells["备注"].Value; fy.费用实体 = piao; fy.费用项编号 = (string)row.Cells["费用项"].Value; fy.金额 = Feng.Utils.ConvertHelper.ToDecimal(row.Cells["金额"].Value).Value; fy.票 = piao; fy.凭证费用明细 = pzfymx; fy.收付标志 = Hd.Model.收付标志.付; fy.相关人编号 = (string)付款对象.SelectedDataValue; if (xiang != null) { fy.箱 = xiang; fy.箱Id = xiang.ID; } (new 业务费用Dao()).Save(rep, fy); pzfymx.费用.Add(fy); } else// if (list.Count == 1) { if (list[0].相关人编号 == pzfymx.相关人编号 && list[0].凭证费用明细 == null) { if (MessageForm.ShowYesNo("货代自编号" + piao.货代自编号 + "费用项" + row.Cells["费用项"].Value.ToString() + "已存在费用,且费用金额不符,是否添加调节款?", "确认")) { 调节业务款 tjk = new 调节业务款(); tjk.备注 = (string)row.Cells["备注"].Value; tjk.费用实体 = piao; tjk.费用项编号 = (string)row.Cells["费用项"].Value; tjk.金额 = Feng.Utils.ConvertHelper.ToDecimal(row.Cells["金额"].Value).Value; tjk.票 = piao; tjk.凭证费用明细 = pzfymx; tjk.收付标志 = Hd.Model.收付标志.付; tjk.相关人编号 = (string)付款对象.SelectedDataValue; if (xiang != null) { tjk.箱 = xiang; tjk.箱Id = xiang.ID; } (new 费用Dao()).Save(rep, tjk); pzfymx.费用.Add(tjk); } else { throw new InvalidUserOperationException("请重新填写货代自编号!"); } } else { throw new InvalidUserOperationException("货代自编号" + piao.货代自编号 + "费用项" + row.Cells["费用项"].Value.ToString() + "已存在的一条费用相关人不符或已经出国凭证,请先修改一致!"); } } } } else { throw new ArgumentException("不合理的凭证用途分类!"); } pz.凭证费用明细.Add(pzfymx); } pz.会计编号 = SystemConfiguration.UserName; pz.会计金额 = sum; pz.金额.币制编号 = "CNY"; pz.金额.数额 = pz.会计金额; pz.凭证类别 = 凭证类别.付款凭证; pz.相关人编号 = (string)付款对象.SelectedDataValue; pz.自动手工标志 = 自动手工标志.手工; (new 凭证Dao()).Save(rep, pz); foreach (凭证费用明细 pzfymx in pz.凭证费用明细) { (new HdBaseDao <凭证费用明细>()).Save(rep, pzfymx); } (new 凭证Dao()).Submit(rep, pz); rep.CommitTransaction(); if (this.ControlManager.ControlCheckExceptionProcess != null) { this.ControlManager.ControlCheckExceptionProcess.ClearAllError(); } this.ControlManager.State = StateType.View; this.ControlManager.OnCurrentItemChanged(); // don't save to database this.ControlManager.EndEdit(false); return(true); } catch (Exception ex) { rep.RollbackTransaction(); ServiceProvider.GetService <IExceptionProcess>().ProcessWithNotify(ex); return(false); } } }
void 承兑汇票Bll_EntityOperating(object sender, OperateArgs <承兑汇票> e) { switch (e.OperateType) { case OperateType.Update: if (e.Entity.托收贴现.HasValue) { if (e.Entity.返回方式.HasValue) { e.Repository.Initialize(e.Entity.费用, e.Entity); if (e.Entity.费用.Count == 0) { decimal?txf = e.Entity.金额 - e.Entity.返回金额; if (!ServiceProvider.GetService <IMessageBox>().ShowYesNo("贴息费为" + txf.Value.ToString("N2") + "元,是否正确?", "确认")) { throw new InvalidUserOperationException("金额填写错误,请重新填写!"); } 非业务费用 fee = new 非业务费用(); fee.费用实体 = e.Entity; fee.费用项编号 = "333"; // 贴息费 fee.金额 = e.Entity.金额 - e.Entity.返回金额; fee.收付标志 = 收付标志.付; fee.相关人编号 = e.Entity.经办人编号; 凭证 pz = new 凭证(); pz.Submitted = true; pz.备注 = e.Entity.备注; pz.出纳编号 = SystemConfiguration.UserName; // e.Entity.返回经手人编号; pz.收支状态 = true; pz.会计编号 = SystemConfiguration.UserName; // e.Entity.返回经手人编号; pz.会计金额 = fee.金额; pz.金额.币制编号 = "CNY"; pz.金额.数额 = pz.会计金额.Value; pz.凭证类别 = 凭证类别.付款凭证; pz.日期 = e.Entity.返回时间.Value; pz.审核人编号 = null; pz.相关人编号 = fee.相关人编号; pz.自动手工标志 = 自动手工标志.承兑汇票; pz.凭证费用明细 = new List <凭证费用明细>(); pz.凭证收支明细 = new List <凭证收支明细>(); pz.审核状态 = true; 凭证费用明细 pzs1 = new 凭证费用明细(); pzs1.费用项编号 = "333"; pzs1.金额 = pz.会计金额; pzs1.凭证 = pz; pzs1.收付标志 = 收付标志.付; pzs1.相关人编号 = pz.相关人编号; pzs1.费用 = new List <费用>(); pzs1.费用.Add(fee); fee.凭证费用明细 = pzs1; pz.凭证费用明细.Add(pzs1); 凭证收支明细 pzs2 = new 凭证收支明细(); pzs2.凭证 = pz; pzs2.金额 = e.Entity.金额; pzs2.收付标志 = 收付标志.付; pzs2.收付款方式 = 收付款方式.银行承兑汇票; pzs2.票据号码 = e.Entity.票据号码; pz.凭证收支明细.Add(pzs2); 凭证收支明细 pzs3 = new 凭证收支明细(); pzs3.凭证 = pz; pzs3.金额 = e.Entity.返回金额; pzs3.收付标志 = 收付标志.收; if (e.Entity.返回方式.Value == 承兑汇票返回方式.银行) { pzs3.收付款方式 = 收付款方式.银行收付; pzs3.银行账户编号 = e.Entity.入款账户编号; } else { pzs3.收付款方式 = 收付款方式.现金; } pz.凭证收支明细.Add(pzs3); (new HdBaseDao <凭证>()).Save(e.Repository, pz); (new HdBaseDao <凭证费用明细>()).Save(e.Repository, pzs1); (new HdBaseDao <凭证收支明细>()).Save(e.Repository, pzs2); (new HdBaseDao <凭证收支明细>()).Save(e.Repository, pzs3); (new 非业务费用Dao()).Save(e.Repository, fee); e.Entity.费用.Add(fee); } } else { e.Repository.Initialize(e.Entity.费用, e.Entity); System.Diagnostics.Debug.Assert(e.Entity.费用.Count <= 1, "承兑汇票费用只有贴息费一项!"); if (e.Entity.费用.Count == 1) { 非业务费用 fee = e.Entity.费用[0] as 非业务费用; 凭证费用明细 pzs1 = fee.凭证费用明细; if (pzs1 != null) { 凭证 pz = pzs1.凭证; e.Repository.Initialize(pz.凭证收支明细, pz); foreach (凭证收支明细 pzs2 in pz.凭证收支明细) { (new HdBaseDao <凭证收支明细>()).Delete(e.Repository, pzs2); } pz.Submitted = false; pz.是否作废 = true; pz.审核状态 = false; pz.收支状态 = false; (new HdBaseDao <凭证>()).Update(e.Repository, pz); (new HdBaseDao <凭证费用明细>()).Update(e.Repository, pzs1); } fee.凭证费用明细 = null; (new 非业务费用Dao()).Delete(e.Repository, fee); e.Entity.费用.Remove(e.Entity.费用[0]); } } } break; } }