public void CreatePayment(Payment payment)
        {
            EntityContext      context  = Session.CreateContext();
            TemplateInfo       template = context.Selete <TemplateInfo>("hr.payment.findDefaultTemplate", 0);
            List <PayItemDO>   items    = context.SelectList <PayItemDO>("hr.payment.findTemplateItems", template.TemplateId);
            List <PayObjectDO> objects  = context.SelectList <PayObjectDO>("hr.payment.findCompanyPersons", payment.CompanyId);

            CommandParameter[] parameters =
            {
                new CommandParameter("CompanyId", payment.CompanyId),
                new CommandParameter("PayMonth",  DateTime.Parse(payment.PayMonth).ToString("yyyyMM"))
            };
            List <PayValueInfo> payValues = context.SelectList <PayValueInfo>("hr.payment.findCompanyPersonsValue", parameters);

            #region 派遣服务费
            foreach (PayObjectDO o in objects)
            {
                PayValueInfo payValue = new PayValueInfo()
                {
                    ItemId   = 6,
                    PersonId = o.ObjectId,
                    PayValue = o.ServiceFee
                };
                payValues.Add(payValue);
            }
            #endregion
            using (context)
            {
                try
                {
                    context.BeginTransaction();
                    payment.TemplateId = template.TemplateId;
                    context.Save <Payment>("hr.payment.insertPayment", payment);
                    foreach (PayItemDO item in items)
                    {
                        item.PaymentId = payment.PayId;
                        context.Save <PayItemDO>("hr.payment.insertPayment.items", item);
                    }
                    foreach (PayObjectDO payObject in objects)
                    {
                        payObject.PaymentId = payment.PayId;
                        context.Save <PayObjectDO>("hr.payment.insertPayment.object", payObject);
                    }
                    foreach (PayValueInfo payValue in payValues)
                    {
                        payValue.PayId = payment.PayId;
                        context.Save <PayValueInfo>("hr.payment.insertPayment.detail", payValue);
                    }

                    context.Commit();
                }
                catch (Exception ex)
                {
                    BlueFramework.Common.Logger.LoggerFactory.CreateDefault().Info(ex.Message);
                    context.Rollback();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 更新发放表
        /// </summary>
        /// <param name="list"></param>
        /// <param name="cmpid"></param>
        /// <param name="tname"></param>
        /// <param name="time"></param>
        /// <param name="count"></param>
        /// <param name="status"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool UpdatePayDetail(List <PayDetailInfo> list, int payid)
        {
            using (EntityContext context = BlueFramework.Blood.Session.CreateContext())
            {
                try
                {
                    context.BeginTransaction();

                    context.Delete("hr.pay.deletePayDetail", payid);

                    Dictionary <string, int> dic = GetIdConfigDic();
                    foreach (PayDetailInfo info in list)
                    {
                        foreach (System.Reflection.PropertyInfo p in info.GetType().GetProperties())
                        {
                            if (dic.ContainsKey(p.Name))
                            {
                                PayValueInfo pvi = new PayValueInfo();
                                pvi.PayId    = payid;
                                pvi.ItemId   = dic[p.Name];
                                pvi.PersonId = info.PersonId;
                                pvi.PayValue = decimal.Parse(p.GetValue(info).ToString());
                                context.Save <PayValueInfo>("hr.pay.insertPayTableDetail", pvi);
                            }
                        }
                    }
                    context.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    context.Rollback();
                    return(false);
                }
            }
        }
Exemple #3
0
 public bool SavePayDetail(List <PayDetailInfo> list, int cmpid, string tname, string time, string count, int status, ref string msg)
 {
     using (EntityContext context = BlueFramework.Blood.Session.CreateContext())
     {
         try
         {
             context.BeginTransaction();
             Models.TemplateInfo temp = context.Selete <Models.TemplateInfo>("hr.template.findTemplateIdByCompanyId", cmpid);
             Payment             pl   = new Payment();
             pl.CompanyId  = cmpid;
             pl.TemplateId = temp.TemplateId;
             pl.PayTitle   = tname;
             pl.PayMonth   = time;
             pl.CreatorId  = UserContext.CurrentUser.UserId;
             pl.CreateTime = DateTime.Now;
             pl.Status     = status;
             if (status == 0)//新建发放表重复校验
             {
                 Payment payinfo = context.SelectListByTemplate <Payment>("hr.pay.findPay", pl)[0];
                 if (payinfo.PayId != 0)
                 {
                     msg += "该公司该月份已创建发放表!<br />";
                     context.Rollback();
                     return(false);
                 }
                 context.Save <Payment>("hr.pay.insertPayTable", pl);
             }
             Dictionary <string, int> dic = GetIdConfigDic();
             foreach (PayDetailInfo info in list)
             {
                 foreach (System.Reflection.PropertyInfo p in info.GetType().GetProperties())
                 {
                     if (dic.ContainsKey(p.Name))
                     {
                         PayValueInfo pvi = new PayValueInfo();
                         pvi.PayId    = pl.PayId;
                         pvi.ItemId   = dic[p.Name];
                         pvi.PersonId = info.PersonId;
                         pvi.PayValue = decimal.Parse(p.GetValue(info).ToString());
                         context.Save <PayValueInfo>("hr.pay.insertPayTableDetail", pvi);
                     }
                 }
             }
             if (status == 2)//归档
             {
                 CompanyAccountInfo cai = new CompanyAccountInfo();
                 cai.AccountBalance = decimal.Parse(count);
                 cai.CompanyId      = cmpid;
                 context.Save <CompanyAccountInfo>("hr.company.updateCompanyBalance", cai);
             }
             context.Commit();
             return(true);
         }
         catch (Exception ex)
         {
             msg += "服务器内部错误,请联系管理员!<br />";
             context.Rollback();
             return(false);
         }
     }
 }
        public bool ImportPayment(int paymentId, DataTable dt, out string message)
        {
            message = string.Empty;
            EntityContext                  context   = Session.CreateContext();
            List <PayItemDO>               items     = context.SelectList <PayItemDO>("hr.payment.findPaymentItems", paymentId);
            List <PayObjectDO>             objects   = context.SelectList <PayObjectDO>("hr.payment.findPaymentPersons", paymentId);
            List <PayValueInfo>            payValues = new List <PayValueInfo>();
            Dictionary <string, PayItemDO> dicItems  = new Dictionary <string, PayItemDO>();

            foreach (PayItemDO pi in items)
            {
                if (pi.Editable == 1)
                {
                    dicItems.Add(pi.ItemCaption, pi);
                }
            }
            int rownum = 1;

            foreach (DataRow dr in dt.Rows)
            {
                int objectId = int.Parse(dr["ID"].ToString());
                foreach (DataColumn column in dt.Columns)
                {
                    bool exist = dicItems.ContainsKey(column.ColumnName);
                    if (!exist)
                    {
                        continue;
                    }
                    string cellValue = dr[column.ColumnName].ToString();
                    if (string.IsNullOrEmpty(cellValue))
                    {
                        continue;
                    }
                    PayItemDO    item = dicItems[column.ColumnName];
                    PayValueInfo pv   = new PayValueInfo();
                    pv.PayId    = paymentId;
                    pv.PersonId = objectId;
                    pv.ItemId   = item.ItemId;
                    decimal payValue = 0;
                    bool    success  = decimal.TryParse(cellValue, out payValue);
                    if (success)
                    {
                        pv.PayValue = payValue;
                    }
                    else
                    {
                        message = message + string.Format("第{0}行{1}数据异常.", rownum, column.ColumnName);
                    }
                    payValues.Add(pv);
                    rownum++;
                }
            }

            using (context)
            {
                try
                {
                    context.BeginTransaction();
                    // 删除可编辑的列数据
                    foreach (var item in dicItems.Values)
                    {
                        PayValueInfo payValue = new PayValueInfo()
                        {
                            PayId  = paymentId,
                            ItemId = item.ItemId
                        };
                        context.Delete <PayValueInfo>("hr.payment.insertPayment.delete", payValue);
                    }
                    // 写入所有数据
                    foreach (PayValueInfo payValue in payValues)
                    {
                        context.Save <PayValueInfo>("hr.payment.insertPayment.detail", payValue);
                    }

                    context.Commit();
                }
                catch (Exception ex)
                {
                    BlueFramework.Common.Logger.LoggerFactory.CreateDefault().Info(ex.Message);
                    message += ex.Message;
                    context.Rollback();
                }
            }
            if (string.IsNullOrEmpty(message))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }