Esempio n. 1
0
        /// <summary>
        /// 修改更新产品和相关供应商信息
        /// </summary>
        /// <param name="product">产品</param>
        /// <param name="vendordata">供应商集合</param>
        /// <param name="udf">自定义字段值</param>
        /// <param name="user_id">操作用户</param>
        /// <returns></returns>
        public ERROR_CODE UpdateProductAndVendor(ivt_product product, VendorData vendordata, List <UserDefinedFieldValue> udf, long user_id)
        {
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {   // 查询不到用户,用户丢失
                return(ERROR_CODE.USER_NOT_FIND);
            }
            //产品更新
            product.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            product.update_user_id = user_id;

            //唯一性校验
            var         propro    = _dal.FindSignleBySql <ivt_product>($"select * from ivt_product where name='{product.name}' and delete_time=0 ");
            ivt_product oldpropro = _dal.FindSignleBySql <ivt_product>($"select * from ivt_product where id='{product.id}' and delete_time=0 ");

            if (propro != null && product.id != propro.id)
            {
                return(ERROR_CODE.EXIST);
            }
            //更新日志
            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.PRODUCT,
                oper_object_id      = product.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                oper_description    = _dal.CompareValue(oldpropro, product),
                remark              = "修改产品信息"
            };                                      // 创建日志

            new sys_oper_log_dal().Insert(add_log); // 插入日志
            if (!_dal.Update(product))
            {
                return(ERROR_CODE.ERROR);
            }
            //供应商更新
            foreach (var ve in vendordata.VENDOR)
            {
                ivt_product_vendor veve = new ivt_product_vendor();
                //删除
                if (ve.operate == 1)
                {
                    var de = _dal1.FindById(ve.id);
                    if (de != null)
                    {
                        de.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                        de.delete_user_id = user_id;
                        _dal1.Update(de);
                        var add_vendor_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.PRODUCT_VENDOR,
                            oper_object_id      = veve.id,// 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.DELETE,
                            oper_description    = _dal1.AddValue(veve),
                            remark              = "删除供应商信息"
                        };                                             // 创建日志
                        new sys_oper_log_dal().Insert(add_vendor_log); // 插入日志
                    }
                }

                //更新
                if (ve.operate == 2)
                {
                    veve = _dal1.FindById(ve.id);
                    if (veve != null)
                    {
                        veve.update_time       = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                        veve.update_user_id    = user_id;
                        veve.product_id        = product.id;
                        veve.is_active         = ve.is_active;
                        veve.is_default        = ve.is_default;
                        veve.vendor_account_id = ve.vendor_account_id;
                        veve.vendor_cost       = ve.vendor_cost;
                        veve.vendor_product_no = ve.vendor_product_no;
                        var oldve = GetSingelVendor(veve.id);
                        _dal1.Update(veve);
                        var add_vendor_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.PRODUCT_VENDOR,
                            oper_object_id      = veve.id,// 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal1.CompareValue(oldve, veve),
                            remark              = "修改供应商信息"
                        };                                             // 创建日志
                        new sys_oper_log_dal().Insert(add_vendor_log); // 插入日志
                    }
                }

                //新增
                if (ve.operate == 3)
                {
                    veve.id                = (int)(_dal.GetNextIdCom());
                    veve.update_time       = veve.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    veve.create_user_id    = user_id;
                    veve.product_id        = product.id;
                    veve.is_active         = ve.is_active;
                    veve.is_default        = ve.is_default;
                    veve.vendor_account_id = ve.vendor_account_id;
                    veve.vendor_cost       = ve.vendor_cost;
                    veve.vendor_product_no = ve.vendor_product_no;
                    _dal1.Insert(veve);
                    var add_vendor_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.PRODUCT_VENDOR,
                        oper_object_id      = veve.id,// 操作对象id
                        oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                        oper_description    = _dal1.AddValue(veve),
                        remark              = "新增供应商信息"
                    };                                             // 创建日志
                    new sys_oper_log_dal().Insert(add_vendor_log); // 插入日志
                }
            }

            var udfBll           = new UserDefinedFieldsBLL();
            var udf_contact_list = udfBll.GetUdf(DicEnum.UDF_CATE.PRODUCTS); // 产品的自定义字段

            udfBll.UpdateUdfValue(UDF_CATE.PRODUCTS, udf_contact_list, product.id, udf, new UserInfoDto {
                id = user.id, name = user.name
            }, OPER_LOG_OBJ_CATE.PRODUCT);

            return(ERROR_CODE.SUCCESS);
        }
Esempio n. 2
0
        /// <summary>
        ///  //删除操作
        /// </summary>
        /// <param name="id"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Delete(long id, long user_id)
        {
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {   // 查询不到用户,用户丢失
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var data = _dal.FindById(id);

            if (data == null)
            {
                return(ERROR_CODE.ERROR);
            }
            var udf_data = _dal.FindById(Convert.ToInt64(data.ext1));
            crm_installed_product_dal dal1 = new crm_installed_product_dal();
            ivt_product_dal           dal2 = new ivt_product_dal();

            var installed_product = dal1.FindListBySql($"select * from crm_installed_product where cate_id={id} and delete_time=0");
            var product           = dal2.FindListBySql($"select * from ivt_product where installed_product_cate_id={id} and delete_time=0");
            var product_cate      = _dal.FindListBySql($"select * from d_general where ext1='{id.ToString()}' and delete_time=0");

            if (installed_product.Count > 0)
            {
                foreach (var i in installed_product)
                {
                    i.cate_id        = 0;
                    i.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    i.update_user_id = user_id;
                    if (dal1.Update(i))
                    {
                        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.CONFIGURAITEM, //
                            oper_object_id      = i.id,                                 // 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal.AddValue(i),
                            remark              = "修改产品配置项"
                        };                                      // 创建日志
                        new sys_oper_log_dal().Insert(add_log); // 插入日志
                    }
                }
            }
            if (product.Count > 0)
            {
                foreach (var i in product)
                {
                    i.installed_product_cate_id = null;
                    i.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    i.update_user_id = user_id;
                    if (dal2.Update(i))
                    {
                        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.PRODUCT, //
                            oper_object_id      = i.id,                           // 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal.AddValue(i),
                            remark              = "修改产品配置项"
                        };                                      // 创建日志
                        new sys_oper_log_dal().Insert(add_log); // 插入日志
                    }
                }
            }
            if (product_cate.Count > 0)
            {
                foreach (var i in product_cate)
                {
                    i.ext1           = null;
                    i.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    i.update_user_id = user_id;
                    if (_dal.Update(i))
                    {
                        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.General_Code, //
                            oper_object_id      = i.id,                                // 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal.AddValue(i),
                            remark              = "修改配置项种类"
                        };                                      // 创建日志
                        new sys_oper_log_dal().Insert(add_log); // 插入日志
                    }
                }
            }

            long time = data.delete_time = udf_data.delete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);

            data.delete_user_id = udf_data.delete_user_id = user.id;
            try
            {
                int n = new sys_udf_group_field_dal().ExecuteSQL($"update sys_udf_group_field set delete_time='{time}' and delete_user_id='{user.id}' where group_id={udf_data.id}");
            }
            catch {
                return(ERROR_CODE.ERROR);
            }
            if (!_dal.Update(data))
            {
                return(ERROR_CODE.ERROR);
            }
            if (!_dal.Update(udf_data))
            {
                return(ERROR_CODE.ERROR);
            }

            return(ERROR_CODE.SUCCESS);
        }