public async Task <Result> AddFactory(reqmodel <AddFactoryModel> reqmodel)
        {
            Result result = new Result {
                code = ErrorCodeConst.ERROR_1018, status = ErrorCodeConst.ERROR_403
            };

            if (!Regex.IsMatch(reqmodel.Data.factory_tel, @"^\d{11}$"))
            {
                result.code = ErrorCodeConst.ERROR_1028;
                return(result);
            }

            string sql_insert = g_sqlMaker.Insert <t_factory>(i =>
                                                              new
            {
                i.factory_name,
                i.factory_person_name,
                i.factory_tel,
                i.status,
                i.state,
            }).ToSQL();

            t_factory factory_model = new t_factory
            {
                factory_name        = reqmodel.Data.factory_name,
                factory_tel         = reqmodel.Data.factory_tel,
                factory_person_name = reqmodel.Data.factory_person_name,
                status = reqmodel.Data.status.GetValueOrDefault((int)EnumStatus.Enable),
                state  = (int)EnumState.Normal
            };
            bool insert_flag = await g_dbHelper.ExecAsync(sql_insert, factory_model) > 0;

            if (!insert_flag)
            {
                result.code = ErrorCodeConst.ERROR_1018;
                return(result);
            }

            result.status = ErrorCodeConst.ERROR_200;
            result.code   = ErrorCodeConst.ERROR_1019;
            return(result);
        }
Example #2
0
        /// <summary>
        /// @xis 添加库存
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <SVResult <int> > AddStock(t_stock model)
        {
            SVResult <int> res = new SVResult <int> {
                state = false
            };

            string sql_insert = g_sqlMaker.Insert <t_stock>(i => new
            {
                i.batch_number,
                i.expiration_date,
                i.factory_id,
                i.freeze_quantity,
                i.instructions,
                i.material_number,
                i.model_number,
                i.package_size,
                i.product_name,
                i.quantity,
                i.remark,
                i.report_card_url,
                i.retest_date,
                i.spare_parts,
                i.state,
                i.status,
                i.unit_price,
                i.util_name
            }).ToSQL();

            //验证
            if (string.IsNullOrWhiteSpace(model.product_name))
            {
                res.code = ErrorCodeConst.ERROR_1044;
                return(res);
            }

            if (model.product_name.Length > 30)
            {
                res.code = ErrorCodeConst.ERROR_1046;
                return(res);
            }

            if (model.factory_id <= 0)
            {
                res.code = ErrorCodeConst.ERROR_1045;
                return(res);
            }
            IFactoryServer factoryServer = new FactoryServerImpl(g_dbHelper, g_logServer);
            t_factory      factory_model = await factoryServer.GetFactoryByIdEnable(g => new { g.id }, model.factory_id);

            if (factory_model == null)
            {
                res.code = ErrorCodeConst.ERROR_1045;
                return(res);
            }

            int id = await g_dbHelper.ExecScalarAsync <int>(sql_insert, model);

            if (id <= 0)
            {
                res.code = ErrorCodeConst.ERROR_1018;
                return(res);
            }
            res.data  = id;
            res.state = true;
            return(res);
        }