Ejemplo n.º 1
0
        protected decimal?searchRate       = null; // 该员工的实际的费率
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var thisId = Request.QueryString["id"];
                if (!string.IsNullOrEmpty(thisId))
                {
                    thisEntry = new sdk_work_entry_dal().FindNoDeleteById(long.Parse(thisId));
                    if (thisEntry != null)
                    {
                        thisTask = new sdk_task_dal().FindNoDeleteById(thisEntry.task_id);
                    }
                }

                if (thisEntry == null || thisTask == null)
                {
                    Response.Write("<script>alert('未找到该工时信息!');window.close();self.opener.location.reload();</script>");
                }
                else
                {
                    if (thisEntry.contract_id != null)
                    {
                        var thisObject = new sdk_work_entry_dal().GetSingle($"select f_get_labor_rate({(long)thisEntry.contract_id},{thisEntry.cost_code_id.ToString()},{thisEntry.role_id.ToString()})");
                        if (thisObject != null)
                        {
                            searchRate = (decimal)thisObject;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 删除服务包相关,不能删除时,返回所有不能删除相关对象数量
 /// </summary>
 public bool DeleteServiceBundle(long serviceId, long userId, ref string faileReason)
 {
     try
     {
         var isbDal        = new ivt_service_bundle_dal();
         var thisSerBundle = isbDal.FindNoDeleteById(serviceId);
         if (thisSerBundle == null)
         {
             return(true);
         }
         var conSerList = new ctt_contract_service_dal().getContractByServiceId(thisSerBundle.id);
         if (conSerList != null && conSerList.Count > 0)
         {
             faileReason += $"{conSerList.Count} 合同\n";
         }
         var quoteItemList = new crm_quote_item_dal().GetItemByObjId(thisSerBundle.id);
         if (quoteItemList != null && quoteItemList.Count > 0)
         {
             faileReason += $"{quoteItemList.Count} 报价项\n";
         }
         var labourList = new sdk_work_entry_dal().GetListByService(thisSerBundle.id);
         if (labourList != null && labourList.Count > 0)
         {
             faileReason += $"{labourList.Count} 工时\n";
         }
         var insProList = new crm_installed_product_dal().GetInsListBySerBunId(thisSerBundle.id);
         if (insProList != null && insProList.Count > 0)
         {
             faileReason += $"{insProList.Count} 配置项\n";
         }
         if (!string.IsNullOrEmpty(faileReason))
         {
             return(false);
         }
         else
         {
             var isbsDal = new ivt_service_bundle_service_dal();
             var serList = GetServiceListByServiceBundleId(thisSerBundle.id);
             if (serList != null && serList.Count > 0)
             {
                 serList.ForEach(_ => {
                     isbsDal.Delete(_);
                 });
             }
             isbDal.SoftDelete(thisSerBundle, userId);
             OperLogBLL.OperLogDelete <ivt_service_bundle>(thisSerBundle, thisSerBundle.id, userId, DTO.DicEnum.OPER_LOG_OBJ_CATE.IVT_SERVICE_BUNDLE, "删除服务包");
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
 void GetLabourInfo(HttpContext context)
 {
     if (!string.IsNullOrEmpty(context.Request.QueryString["id"]))
     {
         var labour = new sdk_work_entry_dal().FindNoDeleteById(long.Parse(context.Request.QueryString["id"]));
         if (labour != null)
         {
             WriteResponseJson(labour);
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 撤销工时审批
        /// </summary>
        public ERROR_CODE REVOKE_LABOUR(long user_id, string ids, out string re)
        {
            re = "";
            if (!string.IsNullOrEmpty(ids))
            {
                var           idArr       = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var           cadDal      = new crm_account_deduction_dal();
                var           sweDal      = new sdk_work_entry_dal();
                var           ccbDal      = new ctt_contract_block_dal();
                StringBuilder returnvalue = new StringBuilder();
                var           timeNow     = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                foreach (var accId in idArr)
                {
                    var thisCad = cadDal.FindNoDeleteById(long.Parse(accId));
                    if (thisCad != null)
                    {
                        if (thisCad.object_id != null)
                        {
                            var cadList = cadDal.GetListByObjectId((long)thisCad.object_id);

                            if (cadList != null && cadList.Count > 0)
                            {
                                foreach (var cad in cadList)
                                {
                                    if (cad.invoice_id != null)
                                    {
                                        var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                                        if (ci != null && ci.is_voided != 1)
                                        {
                                            returnvalue.Append(accId + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                                        }
                                    }
                                }
                            }


                            if (string.IsNullOrEmpty(returnvalue.ToString()))
                            {
                                if (cadList != null && cadList.Count > 0)
                                {
                                    cadList.ForEach(_ => {
                                        RecoveryBlock(_.id, user_id);
                                        cadDal.SoftDelete(_, user_id);
                                        OperLogBLL.OperLogDelete <crm_account_deduction>(_, _.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                                    });
                                    var swe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                                    if (swe != null)
                                    {
                                        var oldSwe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                                        swe.approve_and_post_date    = null;
                                        swe.approve_and_post_user_id = null;
                                        swe.hours_billed_deduction   = null;
                                        swe.hours_rate_deduction     = null;
                                        swe.update_time    = timeNow;
                                        swe.update_user_id = user_id;
                                        sweDal.Update(swe);
                                        OperLogBLL.OperLogUpdate <sdk_work_entry>(swe, oldSwe, swe.id, user_id, OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "修改工时");
                                    }
                                }
                            }
                            else
                            {
                                re = returnvalue.ToString();
                            }
                        }
                        #region  原来的撤销审批的相关逻辑(原来只针对单个条目进行删除,现在批量操作)
                        //if (thisCad.invoice_id!=null)
                        //{
                        //    var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                        //    if (ci!=null&&ci.is_voided != 1)
                        //    {
                        //        returnvalue.Append(accId + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                        //    }
                        //}
                        //else
                        //{
                        //    #region 删除条目信息
                        //    // var oldCad = cadDal.FindNoDeleteById(long.Parse(accId));
                        //    cadDal.SoftDelete(thisCad,user_id);
                        //    OperLogBLL.OperLogDelete<crm_account_deduction>(thisCad, thisCad.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                        //    #endregion

                        //    #region 修改工时表
                        //    if (thisCad.object_id != null)
                        //    {
                        //        var swe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                        //        if (swe != null)
                        //        {
                        //            var oldSwe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                        //            swe.approve_and_post_date = null;
                        //            swe.approve_and_post_user_id = null;
                        //            swe.hours_billed_deduction = null;
                        //            swe.hours_rate_deduction = null;
                        //            swe.update_time = timeNow;
                        //            swe.update_user_id = user_id;
                        //            sweDal.Update(swe);
                        //            OperLogBLL.OperLogUpdate<sdk_work_entry>(swe, oldSwe, swe.id, user_id, OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "修改工时");
                        //        }
                        //    }
                        //    #endregion

                        //    #region 修改预付费信息
                        //    if (thisCad.contract_block_id != null)
                        //    {
                        //        var thisCcb = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                        //        if (thisCcb != null)
                        //        {
                        //            var oldCcb = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                        //            thisCcb.is_billed = 0;
                        //            thisCcb.status_id = 1;
                        //            thisCcb.update_time = timeNow;
                        //            thisCcb.update_user_id = user_id;
                        //            ccbDal.Update(thisCcb);
                        //            OperLogBLL.OperLogUpdate<ctt_contract_block>(thisCcb, oldCcb, thisCcb.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_BLOCK, "修改合同预付");
                        //        }

                        //    }
                        //    #endregion
                        //}
                        #endregion
                    }
                    else
                    {
                    }
                }
            }
            return(ERROR_CODE.SUCCESS);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// /撤销成本审批
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public ERROR_CODE Revoke_CHARGES(long user_id, string ids, out string re)
        {
            re = string.Empty;
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {   // 查询不到用户,用户丢失
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var cadDal = new crm_account_deduction_dal();
            var sweDal = new sdk_work_entry_dal();
            crm_account_deduction  cad         = new crm_account_deduction();
            ctt_contract_block     ccb         = new ctt_contract_block();
            ctt_contract_cost      ccc         = new ctt_contract_cost();
            ctt_contract_cost_dal  ccc_dal     = new ctt_contract_cost_dal();
            ctt_contract_block_dal ccb_dal     = new ctt_contract_block_dal();
            StringBuilder          returnvalue = new StringBuilder();

            //该条目已经生成发票(发票ID:发票ID),请先作废该发票
            if (!string.IsNullOrEmpty(ids))
            {
                var timeNow = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                var idList  = ids.Split(',');
                foreach (var id in idList)
                {
                    var oldcad = cad = GetAccountDed(long.Parse(id));

                    if (cad != null)
                    {
                        if (cad.object_id != null)
                        {
                            var cadList = cadDal.GetListByObjectId((long)cad.object_id);
                            if (cadList != null && cadList.Count > 0)
                            {
                                foreach (var thisCad in cadList)
                                {
                                    if (thisCad.invoice_id != null)
                                    {
                                        var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                                        if (ci != null && ci.is_voided != 1)
                                        {
                                            returnvalue.Append(id + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                                        }
                                    }
                                }
                            }


                            if (string.IsNullOrEmpty(returnvalue.ToString()))
                            {
                                if (cadList != null && cadList.Count > 0)
                                {
                                    cadList.ForEach(_ => {
                                        RecoveryBlock(_.id, user_id);
                                        cadDal.SoftDelete(_, user_id);
                                        OperLogBLL.OperLogDelete <crm_account_deduction>(_, _.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                                    });
                                    var oldccc = ccc = ccc_dal.FindNoDeleteById((long)cad.object_id);
                                    if (ccc != null)
                                    {
                                        // var oldSwe = sweDal.FindNoDeleteById((long)cad.object_id);
                                        ccc.update_time    = timeNow;
                                        ccc.update_user_id = user.id;
                                        ccc.bill_status    = 0;
                                        ccc.extended_price = ccc.unit_price * ccc.quantity;
                                        ccc_dal.Update(ccc);
                                        OperLogBLL.OperLogUpdate <ctt_contract_cost>(ccc, oldccc, ccc.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_COST, "修改合同成本");
                                    }
                                }
                            }
                            else
                            {
                                re = returnvalue.ToString();
                            }
                        }
                    }


                    #region 原有的撤销成本审批相关逻辑
                    //if (cad.invoice_id != null)
                    //{
                    //    var ci = new ctt_invoice_dal().FindNoDeleteById((long)cad.invoice_id);
                    //    if (ci.is_voided != 1)
                    //    {
                    //        returnvalue.Append(id + "条目已经生成发票(发票ID:" + cad.invoice_id + "),请先作废该发票\n");
                    //    }
                    //}
                    //else
                    //{
                    //    cad.delete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //    cad.delete_user_id = user.id;
                    //    var add1_log = new sys_oper_log()
                    //    {
                    //        user_cate = "用户",
                    //        user_id = (int)user.id,
                    //        name = user.name,
                    //        phone = user.mobile == null ? "" : user.mobile,
                    //        oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    //        oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION,
                    //        oper_object_id = cad.id,// 操作对象id
                    //        oper_type_id = (int)OPER_LOG_TYPE.DELETE,
                    //        oper_description = cad_dal.CompareValue(oldcad, cad),
                    //        remark = "删除审批并提交"
                    //    };          // 创建日志
                    //    new sys_oper_log_dal().Insert(add1_log);       // 插入日志
                    //    if (!cad_dal.Update(cad))
                    //    {
                    //        return ERROR_CODE.ERROR;
                    //    }
                    //    //合同成本
                    //    var oldccc = ccc = ccc_dal.FindSignleBySql<ctt_contract_cost>($"select * from ctt_contract_cost where id={cad.object_id} and delete_time=0");
                    //    if (ccc != null)
                    //    {
                    //        ccc.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //        ccc.update_user_id = user.id;
                    //        ccc.bill_status = 0;
                    //        ccc.extended_price = ccc.unit_price * ccc.quantity;
                    //        var add_log = new sys_oper_log()
                    //        {
                    //            user_cate = "用户",
                    //            user_id = (int)user.id,
                    //            name = user.name,
                    //            phone = user.mobile == null ? "" : user.mobile,
                    //            oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    //            oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.CONTRACT_COST,
                    //            oper_object_id = ccc.id,// 操作对象id
                    //            oper_type_id = (int)OPER_LOG_TYPE.UPDATE,
                    //            oper_description = cad_dal.CompareValue(oldccc, ccc),
                    //            remark = "修改合同成本"
                    //        };          // 创建日志
                    //        new sys_oper_log_dal().Insert(add_log);       // 插入日志
                    //        if (!ccc_dal.Update(ccc))
                    //        {
                    //            return ERROR_CODE.ERROR;
                    //        }
                    //        if (cad.contract_block_id != null)
                    //        {
                    //            //合同预付
                    //            var oldccb = ccb = ccb_dal.FindSignleBySql<ctt_contract_block>($" select * from ctt_contract_block where id={cad.contract_block_id} and delete_time=0");
                    //            if (ccb != null)
                    //            {
                    //                ccb.is_billed = 0;
                    //                ccb.status_id = 1;
                    //                ccb.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //                ccb.update_user_id = user.id;
                    //                var add3_log = new sys_oper_log()
                    //                {
                    //                    user_cate = "用户",
                    //                    user_id = (int)user.id,
                    //                    name = user.name,
                    //                    phone = user.mobile == null ? "" : user.mobile,
                    //                    oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    //                    oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.CONTRACT_BLOCK,
                    //                    oper_object_id = ccc.id,// 操作对象id
                    //                    oper_type_id = (int)OPER_LOG_TYPE.UPDATE,
                    //                    oper_description = cad_dal.CompareValue(oldccb, ccb),
                    //                    remark = "修改合同预付"
                    //                };          // 创建日志
                    //                new sys_oper_log_dal().Insert(add3_log);       // 插入日志
                    //                if (!ccb_dal.Update(ccb))
                    //                {
                    //                    return ERROR_CODE.ERROR;
                    //                }
                    //            }
                    //        }
                    //    }

                    //}
                    #endregion
                }
            }
            if (!string.IsNullOrEmpty(returnvalue.ToString()))
            {
                re = returnvalue.ToString();
                return(ERROR_CODE.EXIST);
            }
            return(ERROR_CODE.SUCCESS);
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var id = Request.QueryString["id"];
                thisTask = new sdk_task_dal().FindNoDeleteById(long.Parse(id));
                if (thisTask != null && thisTask.project_id != null)
                {
                    thisBookMark = new IndexBLL().GetSingBook(Request.Url.LocalPath + "?id=" + id, LoginUserId);
                    tvbDto.Add(new DictionaryEntryDto("type", "类型", 0));
                    tvbDto.Add(new DictionaryEntryDto("time", "操作时间", 0));
                    tvbDto.Add(new DictionaryEntryDto("resouName", "员工", 0));
                    tvbDto.Add(new DictionaryEntryDto("workHours", "实际工作时间", 0));
                    tvbDto.Add(new DictionaryEntryDto("notTiltle", "说明/标题", 0));
                    tvbDto.Add(new DictionaryEntryDto("billabled", "是否计费", 0));
                    tvbDto.Add(new DictionaryEntryDto("billed", "已计费", 0));

                    expDto.Add(new DictionaryEntryDto("type_id", "类型", 0));
                    expDto.Add(new DictionaryEntryDto("add_date", "费用日期", 0));
                    expDto.Add(new DictionaryEntryDto("create_user_id", "创建人", 0));
                    expDto.Add(new DictionaryEntryDto("expense_cost_code_id", "费用类别", 0));
                    expDto.Add(new DictionaryEntryDto("amount", "总额", 0));
                    expDto.Add(new DictionaryEntryDto("is_billable", "计费的", 0));
                    expDto.Add(new DictionaryEntryDto("approve_and_post_user_id", "已计费", 0));


                    v_task = new v_task_all_dal().FindById(thisTask.id);
                    if (thisTask.type_id == (int)DicEnum.TASK_TYPE.PROJECT_ISSUE)
                    {
                        taskType = "问题";
                    }
                    else if (thisTask.type_id == (int)DicEnum.TASK_TYPE.PROJECT_TASK)
                    {
                        taskType = "任务";
                    }
                    else
                    {
                        Response.End();
                    }
                    #region 记录浏览历史
                    var account = new CompanyBLL().GetCompany(thisTask.account_id);
                    var history = new sys_windows_history()
                    {
                        title = $"查看{taskType}:" + (thisProject != null ? thisProject.name : "") + " " + thisTask.title + " " + (account != null ? account.name : ""),
                        url   = Request.RawUrl,
                    };
                    new IndexBLL().BrowseHistory(history, LoginUserId);
                    #endregion
                    thisProject = new pro_project_dal().FindNoDeleteById((long)thisTask.project_id);
                    if (thisProject != null)
                    {
                        thisAccount = new crm_account_dal().FindNoDeleteById(thisProject.account_id);
                        if (thisProject.contract_id != null)
                        {
                            thisContract = new ctt_contract_dal().FindNoDeleteById((long)thisProject.contract_id);
                        }
                    }
                    thisTaskResList = new sdk_task_resource_dal().GetTaskResByTaskId(thisTask.id);
                    var roleList = dic.FirstOrDefault(_ => _.Key == "role").Value as List <sys_role>;
                    var sysList  = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value as List <DictionaryEntryDto>;

                    #region 工时备注附件
                    var tasEntryList = new sdk_work_entry_dal().GetByTaskId(thisTask.id);
                    if (tasEntryList != null && tasEntryList.Count > 0)
                    {
                        var newList = (from a in tasEntryList
                                       join b in roleList on a.role_id equals b.id
                                       join c in sysList on a.resource_id equals long.Parse(c.val)
                                       select new TaskViewDto {
                            id = a.id, type = "entry", time = Tools.Date.DateHelper.ConvertStringToDateTime((long)(a.end_time ?? a.start_time)), resouName = c.show + "(" + b.name + ")", workHours = a.hours_worked, notTiltle = a.summary_notes, billabled = a.is_billable == 1?"✓":"", billed = a.approve_and_post_date == null?"": "✓", startDate = Tools.Date.DateHelper.ConvertStringToDateTime((long)a.start_time), workTypeId = a.cost_code_id, contractId = a.contract_id, showOnInv = a.show_on_invoice == 1, serviceId = a.service_id
                        }).ToList();

                        tvdList.AddRange(newList);
                    }
                    var conAttDal      = new com_attachment_dal();
                    var allTaskAttList = new List <com_attachment>();
                    var taskNoteList   = new com_activity_dal().GetActiList($" and (task_id ={thisTask.id} or object_id={thisTask.id} )");
                    if (taskNoteList != null && taskNoteList.Count > 0)
                    {
                        var newList = (from a in taskNoteList
                                       join c in sysList on a.resource_id equals long.Parse(c.val) into temp
                                       from tt in temp.DefaultIfEmpty()
                                       select new TaskViewDto {
                            id = a.id, type = "note", time = Tools.Date.DateHelper.ConvertStringToDateTime(a.create_time), resouName = tt == null ? "" : tt.show, notTiltle = a.name, noteDescr = a.description
                        }).ToList();
                        tvdList.AddRange(newList);

                        foreach (var thisTaskNote in taskNoteList)
                        {
                            var thisNoteAttList = conAttDal.GetAttListByOid(thisTaskNote.id);
                            if (thisNoteAttList != null && thisNoteAttList.Count > 0)
                            {
                                allTaskAttList.AddRange(thisNoteAttList);
                            }
                        }
                    }
                    var taskAttList = conAttDal.GetAttListByOid(thisTask.id);
                    if (taskAttList != null && taskAttList.Count > 0)
                    {
                        allTaskAttList.AddRange(taskAttList);
                    }
                    if (allTaskAttList.Count > 0)
                    {
                        var newList = (from a in allTaskAttList
                                       join c in sysList on a.create_user_id equals long.Parse(c.val) into temp
                                       from tt in temp.DefaultIfEmpty()
                                       select new TaskViewDto {
                            id = a.id, type = "atach", time = Tools.Date.DateHelper.ConvertStringToDateTime(a.create_time), resouName = tt == null?"":tt.show, notTiltle = a.title, fileType = a.type_id
                        }).ToList();
                        tvdList.AddRange(newList);
                    }
                    if (tvdList != null && tvdList.Count > 0)
                    {
                        tvbOrder = Request.QueryString["tvbOrder"];
                        tvdList  = tvdList.OrderBy(_ => _.time).ToList();
                        if (!string.IsNullOrEmpty(tvbOrder))
                        {
                            var tvbOrderArr = tvbOrder.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                            var orderFile   = tvbDto.FirstOrDefault(_ => _.val == tvbOrderArr[0]);
                            if (tvbOrderArr[1] == "desc")
                            {
                                //tvdList = (from a in tvdList
                                //           orderby tvbOrderArr[0]  descending
                                //           select a).ToList();
                                tvdList.Sort(delegate(TaskViewDto t1, TaskViewDto t2) {
                                    return(GetObjectPropertyValue(t2, tvbOrderArr[0]).CompareTo(GetObjectPropertyValue(t1, tvbOrderArr[0])));
                                });
                                orderFile.select = orderFile != null ? 2 : orderFile.select;
                            }
                            else
                            {
                                //tvdList = (from a in tvdList
                                //           orderby tvbOrderArr[0]
                                //           select a).ToList();
                                tvdList.Sort(delegate(TaskViewDto t1, TaskViewDto t2) {
                                    return(GetObjectPropertyValue(t1, tvbOrderArr[0]).CompareTo(GetObjectPropertyValue(t2, tvbOrderArr[0])));
                                });
                                orderFile.select = orderFile != null ? 1 : orderFile.select;
                            }
                        }
                    }
                    #endregion

                    #region 费用
                    taskExpList = new sdk_expense_dal().GetExpByTaskId(thisTask.id);
                    if (taskExpList != null && taskExpList.Count > 0)
                    {
                        taskExpList = taskExpList.OrderByDescending(_ => _.add_date).ToList();
                        expOrder    = Request.QueryString["expOrder"];
                        if (!string.IsNullOrEmpty(expOrder))
                        {
                            var expOrderArr = expOrder.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            var orderFile   = expDto.FirstOrDefault(_ => _.val == expOrderArr[0]);
                            if (expOrderArr[1] == "desc")
                            {
                                //taskExpList = (from a in taskExpList
                                //           orderby expOrderArr[0] descending
                                //           select a).ToList();
                                taskExpList.Sort(delegate(sdk_expense t1, sdk_expense t2) {
                                    return(GetObjectPropertyValue(t2, expOrderArr[0]).CompareTo(GetObjectPropertyValue(t1, expOrderArr[0])));
                                });
                                orderFile.select = orderFile != null ? 2 : orderFile.select;
                            }
                            else
                            {
                                //taskExpList = (from a in taskExpList
                                //           orderby expOrderArr[0]
                                //           select a).ToList();
                                taskExpList.Sort(delegate(sdk_expense t1, sdk_expense t2) {
                                    return(GetObjectPropertyValue(t1, expOrderArr[0]).CompareTo(GetObjectPropertyValue(t2, expOrderArr[0])));
                                });

                                orderFile.select = orderFile != null ? 1 : orderFile.select;
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    Response.End();
                }
            }
            catch (Exception msg)
            {
                Response.End();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 新增附件
        /// </summary>
        /// <param name="objType">对象类型</param>
        /// <param name="objId">对象id</param>
        /// <param name="typeId">附件类型</param>
        /// <param name="title">附件名</param>
        /// <param name="attLink">附件内容</param>
        /// <param name="fileName">上传的文件名</param>
        /// <param name="fileSaveName">文件保存服务器的名称</param>
        /// <param name="contentType">文件类型</param>
        /// <param name="size">文件大小</param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool AddAttachment(int objType, long objId, int typeId, string title, string attLink, string fileName, string fileSaveName, string contentType, int size, long userId, string pubTypeId = "")
        {
            com_attachment att = new com_attachment();


            att.object_type_id = objType;
            att.object_id      = objId;

            // 备注和附件的下级备注和附件不能再添加附件
            if (objType == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES)
            {
                var note = new com_activity_dal().FindById(objId);
                if (note.object_type_id == (int)DicEnum.OBJECT_TYPE.NOTES)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES;
                    att.object_id      = note.object_id;
                }
                else if (note.object_type_id == (int)DicEnum.OBJECT_TYPE.ATTACHMENT)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT;
                    att.object_id      = note.object_id;
                }
            }
            else if (objType == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT)
            {
                var attachment = dal.FindById(objId);
                if (attachment.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES;
                    att.object_id      = attachment.object_id;
                }
                else if (attachment.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT;
                    att.object_id      = attachment.object_id;
                }
            }
            else if (objType == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.LABOUR)
            {
                var labour = new sdk_work_entry_dal().FindById(objId);
                if (labour.parent_id != null)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.LABOUR;
                    att.object_id      = (long)labour.parent_id;
                }
                else if (labour.parent_attachment_id != null)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT;
                    att.object_id      = (long)labour.parent_attachment_id;
                }
                else if (labour.parent_note_id != null)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES;
                    att.object_id      = (long)labour.parent_note_id;
                }
            }

            if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT)
            {
                var attachment = dal.FindById(att.object_id);
                att.account_id = attachment.account_id;
                att.parent_id  = attachment.id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES)
            {
                var note = new com_activity_dal().FindById(att.object_id);
                att.account_id = note.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.OPPORTUNITY)
            {
                var opp = new crm_opportunity_dal().FindById(att.object_id);
                att.account_id = opp.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.SALES_ORDER)
            {
                var so  = new crm_sales_order_dal().FindById(att.object_id);
                var opp = new crm_opportunity_dal().FindById(so.opportunity_id);
                att.account_id = opp.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.CONTRACT)
            {
                var contract = new ctt_contract_dal().FindById(att.object_id);
                att.account_id = contract.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.COMPANY)
            {
                att.account_id = att.object_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.PROJECT)
            {
                var project = new pro_project_dal().FindNoDeleteById(att.object_id);
                att.account_id = project.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.EXPENSE_REPORT)
            {
                // 从报表添加附件 - 默认使用声联(oid=0) 的客户
                var defaultAccount = new CompanyBLL().GetDefaultAccount();
                att.account_id = defaultAccount.id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.TASK)
            {
                var task = new sdk_task_dal().FindNoDeleteById(att.object_id);
                if (task != null)
                {
                    att.account_id = task.account_id;
                    #region 更新客户最后活动时间
                    crm_account thisAccount = new CompanyBLL().GetCompany(task.account_id);
                    if (thisAccount != null)
                    {
                        thisAccount.last_activity_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); new CompanyBLL().EditAccount(thisAccount, userId);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(pubTypeId))
                {
                    att.publish_type_id = int.Parse(pubTypeId);
                }
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.LABOUR)
            {
                var labour = new sdk_work_entry_dal().FindNoDeleteById(att.object_id);
                if (labour == null)
                {
                    return(false);
                }
                var ticket = new sdk_task_dal().FindNoDeleteById(labour.task_id);
                if (ticket == null)
                {
                    return(false);
                }
                att.account_id = ticket.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.KNOWLEDGE)
            {
                var thisArt = new sdk_kb_article_dal().FindNoDeleteById(att.object_id);
                if (thisArt == null)
                {
                    return(false);
                }
                att.account_id = thisArt.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.RESOURCE)
            {
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.CONFIGITEM)
            {
                crm_installed_product insPro = new crm_installed_product_dal().FindNoDeleteById(att.object_id);
                if (insPro == null)
                {
                    return(false);
                }
                att.account_id = insPro.account_id;
            }
            else
            {
                return(false);
            }

            att.id             = dal.GetNextIdCom();
            att.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            att.create_user_id = userId;
            att.update_time    = att.create_time;
            att.update_user_id = userId;
            att.title          = title;
            att.type_id        = typeId;
            if (typeId == (int)DicEnum.ATTACHMENT_TYPE.FILE_LINK ||
                typeId == (int)DicEnum.ATTACHMENT_TYPE.FOLDER_LINK)
            {
                att.uncpath  = attLink;
                att.filename = @"file://" + attLink;
            }
            else if (typeId == (int)DicEnum.ATTACHMENT_TYPE.URL)
            {
                if (attLink.IndexOf(@"http://") == 0)
                {
                    attLink      = attLink.Remove(0, 7);
                    att.urlpath  = attLink;
                    att.filename = @"http://" + attLink;
                }
                else if (attLink.IndexOf(@"https://") == 0)
                {
                    attLink      = attLink.Remove(0, 8);
                    att.urlpath  = attLink;
                    att.filename = @"https://" + attLink;
                }
                else
                {
                    att.urlpath  = attLink;
                    att.filename = @"http://" + attLink;
                }
            }
            else if (typeId == (int)DicEnum.ATTACHMENT_TYPE.ATTACHMENT)
            {
                att.href         = fileSaveName;
                att.filename     = fileName;
                att.sizeinbyte   = size;
                att.content_type = contentType;
            }
            else
            {
                return(false);
            }

            dal.Insert(att);
            OperLogBLL.OperLogAdd <com_attachment>(att, att.id, userId, DicEnum.OPER_LOG_OBJ_CATE.ATTACHMENT, "新增附件");
            return(true);
        }