コード例 #1
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        public bool DeleteList(List <int> idList, int actType, int isDeleted)
        {
            Type type = typeof(T);
            List <CommandInfo> comList = new List <CommandInfo>();

            foreach (int id in idList)
            {
                string strWhere = $"[{type.GetPrimary()}]=@Id";
                string delSql   = "";
                if (actType == 1)
                {
                    delSql = CreateSql.CreateDeleteSql <T>(strWhere);
                }
                else
                {
                    delSql = $"update [{type.GetTName()}] set IsDeleted={isDeleted} where {strWhere}";
                }
                SqlParameter[] paras =
                {
                    new SqlParameter("@Id", id)
                };
                CommandInfo com = new CommandInfo(delSql, false, paras);
                comList.Add(com);
            }
            return(SqlHelper.ExecuteTrans(comList));
        }
コード例 #2
0
        /// <summary>
        /// 修改菜单信息
        /// </summary>
        /// <param name="menuInfo"></param>
        /// <returns></returns>
        public bool UpdateMenuInfo(MenuInfoModel menuInfo, bool blUpdate)
        {
            List <CommandInfo> comList = new List <CommandInfo>();
            string             cols    = "MId,MName,ParentId,ParentName,MKey,MUrl,IsTop,MOrder,MDesp";
            SqlModel           upModel = CreateSql.GetUpdateSqlAndParas(menuInfo, cols, "");

            //修改指定的菜单信息
            comList.Add(new CommandInfo()
            {
                CommandText = upModel.Sql,
                IsProc      = false,
                Paras       = upModel.SqlParaArray
            });
            if (blUpdate)
            {
                string         sqlUpdateParentName = "update MenuInfos set ParentName=@parentName where ParentId=@menuId";
                SqlParameter[] paras =
                {
                    new SqlParameter("@parentName", menuInfo.MName),
                    new SqlParameter("@menuId",     menuInfo.MId)
                };
                comList.Add(new CommandInfo()
                {
                    CommandText = sqlUpdateParentName,
                    IsProc      = false,
                    Paras       = paras
                });
            }
            return(SqlHelper.ExecuteTrans(comList));
        }
コード例 #3
0
        /// <summary>
        /// 添加实体信息
        /// </summary>
        /// <param name="t"></param>
        /// <param name="strCols">插入列名字符串,若为空,则全插入</param>
        /// <returns></returns>
        public int Add(T t, string strCols, int isReturn)
        {
            if (t == null)
            {
                return(0);
            }
            //获取生成的sql和参数列表
            SqlModel insert = CreateSql.GetInsertSqlAndParas <T>(t, strCols, isReturn);

            //执行sql命令
            if (isReturn == 0)
            {
                return(SqlHelper.ExecuteNonQuery(insert.Sql, 1, insert.SqlParaArray));
            }
            else
            {
                object oId = SqlHelper.ExecuteScalar(insert.Sql, 1, insert.SqlParaArray);
                if (oId != null && oId.ToString() != "")
                {
                    return(oId.GetInt());
                }
                else
                {
                    return(0);
                }
            }
        }
コード例 #4
0
ファイル: StockStoreDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 添加入库单
        /// </summary>
        /// <param name="stockInfo"></param>
        /// <param name="stockGoodsList"></param>
        /// <returns>入库单编号 与 入库单号</returns>
        public string AddStockInfo(StockStoreInfoModel stockInfo, List <StStockGoodsInfoModel> stockGoodsList)
        {
            //入库单表的列名
            string cols = "StoreId,DealPerson,Remark,StockNo,Creator,CreateTime";
            //插入期初库存商品列表的列名
            string sgCols = "StockId,GoodsId,StCount,StPrice,StAmount,Remark";

            //生成入库单号---保存入库单信息--保存入库商品明细列表
            return(SqlHelper.ExecuteTrans <string>(cmd =>
            {
                try
                {
                    //获取生成的入库单号
                    cmd.CommandText = "makeStockNo";
                    cmd.CommandType = CommandType.StoredProcedure;
                    object stockNo = cmd.ExecuteScalar();
                    cmd.Parameters.Clear();
                    if (stockNo != null && stockNo.ToString() != "")
                    {
                        //保存入库单
                        stockInfo.StockNo = stockNo.ToString();
                        SqlModel inStock = CreateSql.GetInsertSqlAndParas <StockStoreInfoModel>(stockInfo, cols, 1);
                        cmd.CommandText = inStock.Sql;
                        foreach (var p in inStock.SqlParaArray)
                        {
                            cmd.Parameters.Add(p);
                        }
                        cmd.CommandType = CommandType.Text;
                        object oStockId = cmd.ExecuteScalar();
                        cmd.Parameters.Clear();

                        if (oStockId != null && oStockId.GetInt() > 0)
                        {
                            //入库商品明细保存
                            foreach (StStockGoodsInfoModel si in stockGoodsList)
                            {
                                si.StockId = oStockId.GetInt();
                                SqlModel inStockGoods = CreateSql.GetInsertSqlAndParas <StStockGoodsInfoModel>(si, sgCols, 0);
                                cmd.CommandText = inStockGoods.Sql;
                                cmd.CommandType = CommandType.Text;
                                foreach (var p in inStockGoods.SqlParaArray)
                                {
                                    cmd.Parameters.Add(p);
                                }
                                cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();
                            }
                        }
                        cmd.Transaction.Commit();
                        return oStockId.ToString() + "," + stockNo.ToString();
                    }
                    return "";
                }
                catch (Exception ex)
                {
                    cmd.Transaction.Rollback();
                    throw new Exception("执行添加入库单异常!", ex);
                }
            }));
        }
コード例 #5
0
        /// <summary>
        /// 修改单位信息 isUpdateName:单位名称是否修改
        /// </summary>
        /// <param name="guInfo"></param>
        /// <returns></returns>
        public bool UpdatGoodsUnit(GoodsUnitInfoModel guInfo, bool isUpdateName, string oldName)
        {
            string cols = "GUnitId,GUnitName,GUnitPYNo,GUnitOrder";

            if (!isUpdateName)
            {
                return(Update(guInfo, cols, ""));
            }
            else
            {
                List <CommandInfo> list    = new List <CommandInfo>();
                SqlModel           upModel = CreateSql.GetUpdateSqlAndParas(guInfo, cols, "");
                SqlParameter[]     paras   =
                {
                    new SqlParameter("@GUnit",    guInfo.GUnitName),
                    new SqlParameter("@OldGUnit", oldName),
                };
                list.Add(new CommandInfo()
                {
                    CommandText = upModel.Sql,
                    IsProc      = false,
                    Paras       = upModel.SqlParaArray
                });
                list.Add(new CommandInfo()
                {
                    CommandText = "update GoodsInfos set GUnit=@GUnit where GUnit=@OldGUnit",
                    IsProc      = false,
                    Paras       = paras
                });
                return(SqlHelper.ExecuteTrans(list));
            }
        }
コード例 #6
0
ファイル: GoodsTypeDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 更新商品类别信息
        /// </summary>
        /// <param name="gtInfo"></param>
        /// <param name="blUpdate"></param>
        /// <returns></returns>
        public bool UpdateGoodsType(GoodsTypeInfoModel gtInfo, bool blUpdate)
        {
            List <CommandInfo> list    = new List <CommandInfo>();
            string             cols    = "GTypeId,GTypeName,ParentId,ParentName,GTypeNo,GTPYNo,GTOrder";
            SqlModel           upModel = CreateSql.GetUpdateSqlAndParas(gtInfo, cols, "");

            list.Add(new CommandInfo()
            {
                CommandText = upModel.Sql,
                IsProc      = false,
                Paras       = upModel.SqlParaArray
            });
            if (blUpdate)
            {
                SqlParameter[] paras =
                {
                    new SqlParameter("@ParentName", gtInfo.GTypeName),
                    new SqlParameter("@ParentId",   gtInfo.GTypeId)
                };
                list.Add(new CommandInfo()
                {
                    CommandText = "update GoodsTypeInfos set ParentName=@ParentName where ParentId=@ParentId",
                    IsProc      = false,
                    Paras       = paras
                });
            }
            return(SqlHelper.ExecuteTrans(list));
        }
コード例 #7
0
ファイル: GoodsDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="goodsInfo"></param>
        /// <returns></returns>
        public bool AddGoodsInfo(GoodsInfoModel goodsInfo)
        {
            string     cols     = "GoodsName,GoodsNo,GoodsPYNo,GoodsSName,GoodsTXNo,GUnit,GTypeId,GProperties,IsStopped,RetailPrice,LowPrice,PrePrice,DisCount,BidPrice,Remark,GoodsPic,Creator";
            SqlModel   insert   = CreateSql.GetInsertSqlAndParas <GoodsInfoModel>(goodsInfo, cols, 1);
            StoreDAL   storeDAL = new StoreDAL();
            List <int> storeIds = storeDAL.GetAllStoreIds();

            return(SqlHelper.ExecuteTrans <bool>(cmd =>
            {
                try
                {
                    cmd.CommandText = insert.Sql;
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Clear();
                    foreach (var p in insert.SqlParaArray)
                    {
                        cmd.Parameters.Add(p);
                    }
                    object oId = cmd.ExecuteScalar();
                    cmd.Parameters.Clear();
                    if (oId != null && oId.ToString() != "")
                    {
                        int goodsId = oId.GetInt();
                        string sql = "insert into StoreGoodsStockInfos (StoreId,GoodsId,Creator) values(@storeId,@goodsId,@creator)";
                        foreach (int storeId in storeIds)
                        {
                            cmd.CommandText = sql;
                            cmd.CommandType = CommandType.Text;
                            cmd.Parameters.Add(new SqlParameter("@storeId", storeId));
                            cmd.Parameters.Add(new SqlParameter("@goodsId", goodsId));
                            cmd.Parameters.Add(new SqlParameter("@creator", goodsInfo.Creator));
                            cmd.ExecuteNonQuery();
                            cmd.Parameters.Clear();
                        }
                        //添加总库存记录
                        cmd.CommandText = sql;
                        cmd.CommandType = CommandType.Text;
                        int sId = 0;
                        cmd.Parameters.Add(new SqlParameter("@storeId", sId));
                        cmd.Parameters.Add(new SqlParameter("@goodsId", goodsId));
                        cmd.Parameters.Add(new SqlParameter("@creator", goodsInfo.Creator));
                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();
                    }
                    cmd.Transaction.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    cmd.Transaction.Rollback();
                    throw new Exception("添加商品执行异常!", ex);
                }
            }));
        }
コード例 #8
0
        /// <summary>
        /// 按条件查询获取实体信息
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="strCols"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        public T GetModel(string strWhere, string strCols, params SqlParameter[] paras)
        {
            //生成查询语句
            string selSql = CreateSql.CreateSelectSql <T>(strWhere, strCols);
            //生成Reader对象
            SqlDataReader reader = SqlHelper.ExecuteReader(selSql, 1, paras);
            //转换为实体对象
            T model = DbConvert.SqlDataReaderToModel <T>(reader, strCols);

            //关闭阅读器
            reader.Close();
            return(model);
        }
コード例 #9
0
ファイル: UserDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="urList"></param>
        /// <returns></returns>
        public bool AddUserInfo(UserInfoModel userInfo, List <UserRoleInfoModel> urList)
        {
            string   colUsers = "UserName,UserPwd,UserState,Creator";
            SqlModel inUser   = CreateSql.GetInsertSqlAndParas(userInfo, colUsers, 1);

            return(SqlHelper.ExecuteTrans <bool>(cmd =>
            {
                try
                {
                    cmd.CommandText = inUser.Sql;
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Clear();
                    foreach (var p in inUser.SqlParaArray)
                    {
                        cmd.Parameters.Add(p);
                    }
                    object oId = cmd.ExecuteScalar();
                    cmd.Parameters.Clear();
                    if (oId != null && oId.ToString() != "")
                    {
                        int userId = oId.GetInt();
                        if (urList.Count > 0)
                        {
                            string colsUserRole = "UserId,RoleId,Creator";
                            foreach (var ur in urList)
                            {
                                ur.UserId = userId;
                                SqlModel inUserRole = CreateSql.GetInsertSqlAndParas <UserRoleInfoModel>(ur, colsUserRole, 0);
                                cmd.CommandText = inUserRole.Sql;
                                cmd.CommandType = CommandType.Text;
                                cmd.Parameters.Clear();
                                foreach (var p in inUserRole.SqlParaArray)
                                {
                                    cmd.Parameters.Add(p);
                                }
                                cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();
                            }
                        }
                    }
                    cmd.Transaction.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    cmd.Transaction.Rollback();
                    throw new Exception("添加用户执行异常!", ex);
                }
            }));
        }
コード例 #10
0
        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="list"></param>
        /// <param name="strCols"></param>
        /// <returns></returns>
        public bool AddList(List <T> list, string strCols)
        {
            if (list == null || list.Count == 0)
            {
                return(false);
            }
            List <CommandInfo> comList = new List <CommandInfo>();

            foreach (T t in list)
            {
                SqlModel    insert = CreateSql.GetInsertSqlAndParas <T>(t, strCols, 0);
                CommandInfo com    = new CommandInfo(insert.Sql, false, insert.SqlParaArray);
                comList.Add(com);
            }
            return(SqlHelper.ExecuteTrans(comList));
        }
コード例 #11
0
        /// <summary>
        /// 执行分页查询 按类别编号 关键字查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="typeId"></param>
        /// <param name="keywords"></param>
        /// <param name="strCols"></param>
        /// <param name="proName"></param>
        /// <param name="startIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public DataSet GetPageDs <S>(string strWhere, int typeId, string keywords, string strCols, string proName, int startIndex, int pageSize)
        {
            List <SqlParameter> listParas = new List <SqlParameter>();

            listParas.Add(new SqlParameter("@typeId", typeId));
            listParas.Add(new SqlParameter("@keywords", keywords));

            string sql = CreateSql.CreateRowsSelectSql <S>(strWhere, strCols);

            listParas.Add(new SqlParameter("@sql", sql));
            listParas.Add(new SqlParameter("@startIndex", startIndex));
            listParas.Add(new SqlParameter("@endIndex", startIndex + pageSize - 1));
            DataSet ds = GetDs(proName, 2, listParas.ToArray());

            return(ds);
        }
コード例 #12
0
ファイル: UserDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="urList"></param>
        /// <param name="urListNew"></param>
        /// <returns></returns>
        public bool UpdateUserInfo(UserInfoModel userInfo, List <UserRoleInfoModel> urList, List <UserRoleInfoModel> urListNew)
        {
            List <CommandInfo> comList  = new List <CommandInfo>();
            string             colsUser = "******";

            if (!string.IsNullOrEmpty(userInfo.UserPwd))
            {
                colsUser += ",UserPwd";
            }
            colsUser += ",UserState";
            SqlModel upUser = CreateSql.GetUpdateSqlAndParas(userInfo, colsUser, "");

            //修改用户信息
            comList.Add(new CommandInfo()
            {
                CommandText = upUser.Sql,
                IsProc      = false,
                Paras       = upUser.SqlParaArray
            });
            if (urList.Count > 0)
            {
                //删除取消的角色关系数据
                string roleIds = string.Join(",", urList.Select(ur => ur.RoleId));
                comList.Add(new CommandInfo()
                {
                    CommandText = $"delete from UserRoleInfos where RoleId not in ({roleIds}) and UserId={userInfo.UserId}",
                    IsProc      = false
                });
            }
            if (urListNew.Count > 0)
            {
                //新增新设置的角色关系
                string colsUserRole = "UserId,RoleId,Creator";
                foreach (var ur in urListNew)
                {
                    SqlModel inUserRole = CreateSql.GetInsertSqlAndParas <UserRoleInfoModel>(ur, colsUserRole, 0);
                    comList.Add(new CommandInfo()
                    {
                        CommandText = inUserRole.Sql,
                        IsProc      = false,
                        Paras       = inUserRole.SqlParaArray
                    });
                }
            }

            return(SqlHelper.ExecuteTrans(comList));
        }
コード例 #13
0
        /// <summary>
        /// 按条件查询返回实体列表
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="strCols">查询字段</param>
        /// <param name="paras">参数数组</param>
        /// <returns>List<T></returns>
        public List <T> GetModelList(string strWhere, string strCols, params SqlParameter[] paras)
        {
            if (string.IsNullOrEmpty(strWhere))
            {
                strWhere = "1=1";
            }
            //生成查询语句
            string selSql = CreateSql.CreateSelectSql <T>(strWhere, strCols);
            //生成Reader
            SqlDataReader reader = SqlHelper.ExecuteReader(selSql, 1, paras);
            //转换为List<T>列表
            List <T> list = DbConvert.SqlDataReaderToList <T>(reader, strCols);

            //关闭阅读器
            reader.Close();
            return(list);
        }
コード例 #14
0
ファイル: StoreGoodsStockDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 保存上下限设置
        /// </summary>
        /// <param name="goodsStockList"></param>
        /// <returns></returns>
        public bool SetGoodsStockUpDown(List <StoreGoodsStockInfoModel> goodsStockList)
        {
            string             upCols = "StoreGoodsId,StockUp,StockDown";
            List <CommandInfo> list   = new List <CommandInfo>();

            foreach (var gupdown in goodsStockList)
            {
                SqlModel sqlModel = CreateSql.GetUpdateSqlAndParas(gupdown, upCols, "");
                list.Add(new CommandInfo()
                {
                    CommandText = sqlModel.Sql,
                    IsProc      = false,
                    Paras       = sqlModel.SqlParaArray
                });
            }
            return(SqlHelper.ExecuteTrans(list));
        }
コード例 #15
0
        /// <summary>
        /// 修改信息实体
        /// </summary>
        /// <param name="t"></param>
        /// <param name="strCols">要修改的列</param>
        /// <param name="strWhere">条件 </param>
        /// <returns></returns>
        public bool Update(T t, string strCols, string strWhere, params SqlParameter[] paras)
        {
            if (t == null)
            {
                return(false);
            }
            //获取生成的sql和参数列表
            SqlModel            update    = CreateSql.GetUpdateSqlAndParas <T>(t, strCols, strWhere);
            List <SqlParameter> listParas = update.SqlParaArray.ToList();

            if (paras != null && paras.Length > 0)
            {
                listParas.AddRange(paras);
            }
            //执行sql命令
            return(SqlHelper.ExecuteNonQuery(update.Sql, 1, listParas.ToArray()) > 0);
        }
コード例 #16
0
        /// <summary>
        /// 添加仓库信息
        /// </summary>
        /// <param name="storeInfo"></param>
        /// <param name="goodsIds">所有商品的编号集合</param>
        /// <returns></returns>
        public bool AddStoreInfo(StoreInfoModel storeInfo, List <int> goodsIds)
        {
            string   cols     = "StoreNo,StoreName,STypeId,StorePYNo,StoreOrder,StoreRemark,Creator";
            SqlModel insert   = CreateSql.GetInsertSqlAndParas <StoreInfoModel>(storeInfo, cols, 1);
            GoodsDAL goodsDAL = new GoodsDAL();

            return(SqlHelper.ExecuteTrans <bool>(cmd =>
            {
                try
                {
                    cmd.CommandText = insert.Sql;
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Clear();
                    foreach (var p in insert.SqlParaArray)
                    {
                        cmd.Parameters.Add(p);
                    }
                    object oId = cmd.ExecuteScalar();
                    cmd.Parameters.Clear();
                    if (oId != null && oId.ToString() != "")
                    {
                        int storeId = oId.GetInt();
                        string sql = "insert into StoreGoodsStockInfos (StoreId,GoodsId,Creator) values(@storeId,@goodsId,@creator)";
                        foreach (int goodsId in goodsIds)
                        {
                            cmd.CommandText = sql;
                            cmd.CommandType = CommandType.Text;
                            cmd.Parameters.Add(new SqlParameter("@storeId", storeId));
                            cmd.Parameters.Add(new SqlParameter("@goodsId", goodsId));
                            cmd.Parameters.Add(new SqlParameter("@creator", storeInfo.Creator));
                            cmd.ExecuteNonQuery();
                            cmd.Parameters.Clear();
                        }
                    }
                    cmd.Transaction.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    cmd.Transaction.Rollback();
                    throw new Exception("添加仓库执行异常!", ex);
                }
            }));
        }
コード例 #17
0
ファイル: ToolGroupDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 修改工具组数据的删除状态
        /// </summary>
        /// <param name="tgIds"></param>
        /// <param name="delType"></param>
        /// <param name="isDeleted"></param>
        /// <returns></returns>
        public bool UpdateToolGroupDeleteState(List <int> tgIds, int delType, int isDeleted)
        {
            string delSql   = "";
            string ids      = string.Join(",", tgIds);
            string strWhere = $" and  TGroupId in ({ids})";

            if (delType == 0)
            {
                delSql = CreateSql.CreateLogicDeleteSql <ToolGroupInfoModel>(strWhere, isDeleted);
            }
            else if (delType == 1)
            {
                delSql = CreateSql.CreateDeleteSql <ToolGroupInfoModel>(strWhere);
            }
            List <string> list = new List <string>();

            list.Add(delSql);
            return(SqlHelper.ExecuteTrans(list));
        }
コード例 #18
0
        /// <summary>
        /// 按条件删除数据(假删除,包含可以恢复)
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="paras">参数列表</param>
        /// <returns></returns>
        public bool Delete(int actType, string strWhere, int isDeleted, SqlParameter[] paras)
        {
            Type   type   = typeof(T);
            string delSql = "";

            if (actType == 1)
            {
                delSql = CreateSql.CreateDeleteSql <T>(strWhere);
            }
            else
            {
                delSql = $"update [{type.GetTName()}] set IsDeleted={isDeleted} where {strWhere}";
            }
            List <CommandInfo> list = new List <CommandInfo>();

            list.Add(new CommandInfo()
            {
                CommandText = delSql,
                IsProc      = false,
                Paras       = paras
            });
            return(SqlHelper.ExecuteTrans(list));
        }
コード例 #19
0
ファイル: SaleOutStoreDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 添加销售单
        /// </summary>
        /// <param name="saleInfo"></param>
        /// <param name="saleGoodsList"></param>
        /// <returns>销售单编号 与 销售单号</returns>
        public string AddSaleOutStoreInfo(SaleOutStoreInfoModel saleInfo, List <SaleGoodsInfoModel> saleGoodsList)
        {
            //销售单表的列名
            string cols = "UnitId,StoreId,DealPerson,PayDesp,ThisAmount,Remark,TotalAmount,YHAmount,SaleOutNo,Creator,CreateTime";

            if (saleInfo.PayTime != null)
            {
                cols += ",PayTime,IsPayed,IsPayFull";
            }
            //插入销售商品列表的列名
            string sgCols = "SaleId,GoodsId,GUnit,Count,SalePrice,Amount,Remark";

            //生成销售单号---保存销售单信息--保存销售商品明细列表
            return(SqlHelper.ExecuteTrans <string>(cmd =>
            {
                try
                {
                    //获取生成的销售单号
                    cmd.CommandText = "makeSaleNo";
                    cmd.CommandType = CommandType.StoredProcedure;
                    object saleNo = cmd.ExecuteScalar();
                    cmd.Parameters.Clear();
                    if (saleNo != null && saleNo.ToString() != "")
                    {
                        //保存销售单
                        saleInfo.SaleOutNo = saleNo.ToString();
                        SqlModel inStock = CreateSql.GetInsertSqlAndParas <SaleOutStoreInfoModel>(saleInfo, cols, 1);
                        cmd.CommandText = inStock.Sql;
                        foreach (var p in inStock.SqlParaArray)
                        {
                            cmd.Parameters.Add(p);
                        }
                        cmd.CommandType = CommandType.Text;
                        object oSaleId = cmd.ExecuteScalar();
                        cmd.Parameters.Clear();

                        if (oSaleId != null && oSaleId.GetInt() > 0)
                        {
                            //出库商品明细保存
                            foreach (SaleGoodsInfoModel si in saleGoodsList)
                            {
                                si.SaleId = oSaleId.GetInt();
                                SqlModel inSaleGoods = CreateSql.GetInsertSqlAndParas <SaleGoodsInfoModel>(si, sgCols, 0);
                                cmd.CommandText = inSaleGoods.Sql;
                                cmd.CommandType = CommandType.Text;
                                foreach (var p in inSaleGoods.SqlParaArray)
                                {
                                    cmd.Parameters.Add(p);
                                }
                                cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();
                            }
                        }
                        cmd.Transaction.Commit();
                        return oSaleId.ToString() + "," + saleNo.ToString();
                    }
                    return "";
                }
                catch (Exception ex)
                {
                    cmd.Transaction.Rollback();
                    throw new Exception("执行添加销售单异常!", ex);
                }
            }));
        }
コード例 #20
0
ファイル: StockStoreDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 更新入库单信息
        /// </summary>
        /// <param name="stockInfo"></param>
        /// <param name="stockGoodsList"></param>
        /// <returns></returns>
        public bool UpdateStockInfo(StockStoreInfoModel stockInfo, List <StStockGoodsInfoModel> stockGoodsList)
        {
            string             cols    = "StockId,StoreId,DealPerson,Remark";
            string             sgCols  = "StockId,GoodsId,StCount,StPrice,StAmount,Remark";
            List <CommandInfo> comList = new List <CommandInfo>();
            SqlModel           upStock = CreateSql.GetUpdateSqlAndParas <StockStoreInfoModel>(stockInfo, cols, "");

            //修改入库单信息
            comList.Add(new CommandInfo()
            {
                CommandText = upStock.Sql,
                IsProc      = false,
                Paras       = upStock.SqlParaArray
            });
            //删除已移除的商品明细数据

            //商品明细编号集合字符串
            string goodsIds = string.Join(",", stockGoodsList.Select(g => g.GoodsId));

            comList.Add(new CommandInfo()
            {
                CommandText = $"delete from StStockGoodsInfos where StockId ={stockInfo.StockId} and GoodsId not in ({goodsIds})",
                IsProc      = false
            });

            //明细商品列表保存:修改、添加 两种
            foreach (StStockGoodsInfoModel sg in stockGoodsList)
            {
                if (sgDAL.ExistsGoods(stockInfo.StockId, sg.GoodsId))
                {
                    string         upSql = "update StStockGoodsInfos set StCount=@count,StPrice=@stPrice,StAmount=@stAmount,Remark=@remark where StockId=@stockId and GoodsId=@goodsId";
                    SqlParameter[] paras =
                    {
                        new SqlParameter("@stockId",  stockInfo.StockId),
                        new SqlParameter("@goodsId",  sg.GoodsId),
                        new SqlParameter("@count",    sg.StCount),
                        new SqlParameter("@stPrice",  sg.StPrice),
                        new SqlParameter("@remark",   sg.Remark),
                        new SqlParameter("@stAmount", sg.StAmount)
                    };
                    comList.Add(new CommandInfo()
                    {
                        CommandText = upSql,
                        IsProc      = false,
                        Paras       = paras
                    });
                }
                else//新增处理
                {
                    sg.StockId = stockInfo.StockId;
                    SqlModel inStStockGoods = CreateSql.GetInsertSqlAndParas <StStockGoodsInfoModel>(sg, sgCols, 0);
                    comList.Add(new CommandInfo()
                    {
                        CommandText = inStStockGoods.Sql,
                        IsProc      = false,
                        Paras       = inStStockGoods.SqlParaArray
                    });
                }
            }
            return(SqlHelper.ExecuteTrans(comList));
        }
コード例 #21
0
 /// <summary>
 /// 保存权限数据
 /// </summary>
 /// <param name="roleId"></param>
 /// <param name="rmList"></param>
 /// <param name="rtmList"></param>
 /// <returns></returns>
 public bool SetRoleRight(int roleId, List <RoleMenuInfoModel> rmList, List <RoleTMenuInfoModel> rtmList)
 {
     //先删除角色相关的权限数据  检查 ---是否存在这么一条关系数据,否---插入   不插入
     return(SqlHelper.ExecuteTrans <bool>(cmd =>
     {
         try
         {
             if (rmList.Count > 0)
             {
                 string noIds = string.Join(",", rmList.Select(rm => rm.MId));
                 cmd.CommandText = $"delete from RoleMenuInfos  where MId not in ({noIds}) and RoleId={roleId}  and IsDeleted=0";
                 cmd.ExecuteNonQuery();
                 foreach (var rm in rmList)
                 {
                     cmd.CommandText = $"select count(1) from RoleMenuInfos where RoleId={rm.RoleId} and MId = {rm.MId} and IsDeleted=0";
                     object oCount = cmd.ExecuteScalar();
                     if (oCount != null && oCount.ToString() != "")
                     {
                         int count = oCount.GetInt();
                         if (count == 0)
                         {
                             SqlModel insertModel = CreateSql.GetInsertSqlAndParas(rm, "MId,RoleId,Creator", 0);
                             cmd.CommandText = insertModel.Sql;
                             foreach (var p in insertModel.SqlParaArray)
                             {
                                 cmd.Parameters.Add(p);
                             }
                             cmd.ExecuteNonQuery();
                             cmd.Parameters.Clear();
                         }
                         else
                         {
                             continue;
                         }
                     }
                 }
             }
             if (rtmList.Count > 0)
             {
                 string noIds = string.Join(",", rtmList.Select(rtm => rtm.TMenuId));
                 cmd.CommandText = $"delete from RoleTMenuInfos  where TMenuId not in ({noIds}) and RoleId={roleId}  and IsDeleted=0";
                 cmd.ExecuteNonQuery();
                 foreach (var rtm in rtmList)
                 {
                     cmd.CommandText = $"select count(1) from RoleTMenuInfos where RoleId={rtm.RoleId} and TMenuId = {rtm.TMenuId} and IsDeleted=0";
                     object oCount = cmd.ExecuteScalar();
                     if (oCount != null && oCount.ToString() != "")
                     {
                         int count = oCount.GetInt();
                         if (count == 0)
                         {
                             SqlModel insertModel = CreateSql.GetInsertSqlAndParas(rtm, "TMenuId,RoleId,Creator", 0);
                             cmd.CommandText = insertModel.Sql;
                             foreach (var p in insertModel.SqlParaArray)
                             {
                                 cmd.Parameters.Add(p);
                             }
                             cmd.ExecuteNonQuery();
                             cmd.Parameters.Clear();
                         }
                         else
                         {
                             continue;
                         }
                     }
                 }
             }
             cmd.Transaction.Commit();
             return true;
         }
         catch (Exception ex)
         {
             cmd.Transaction.Rollback();
             throw new Exception("保存权限数据,执行异常!", ex);
         }
     }));
     //保存权限数据
 }
コード例 #22
0
ファイル: PerchaseInStoreDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 添加采购单
        /// </summary>
        /// <param name="perchaseInfo"></param>
        /// <param name="perGoodsList"></param>
        /// <returns>采购单编号 与 采购单号</returns>
        public string AddPerchaseInfo(PerchaseInStoreInfoModel perchaseInfo, List <PerchaseGoodsInfoModel> perGoodsList)
        {
            //采购单表的列名
            string cols = "UnitId,StoreId,DealPerson,PayDesp,ThisAmount,Remark,TotalAmount,YHAmount,PerchaseNo,Creator,CreateTime";

            if (perchaseInfo.PayTime != null)
            {
                cols += ",PayTime,IsPayed,IsPayFull";
            }
            //插入采购商品列表的列名
            string sgCols = "PerId,GoodsId,GUnit,Count,PerPrice,Amount,Remark";

            //生成采购单号---保存采购单信息--保存采购商品明细列表
            return(SqlHelper.ExecuteTrans <string>(cmd =>
            {
                try
                {
                    //获取生成的采购单号
                    cmd.CommandText = "makePerNo";
                    cmd.CommandType = CommandType.StoredProcedure;
                    object perNo = cmd.ExecuteScalar();
                    cmd.Parameters.Clear();
                    if (perNo != null && perNo.ToString() != "")
                    {
                        //保存入库单
                        perchaseInfo.PerchaseNo = perNo.ToString();
                        SqlModel inStock = CreateSql.GetInsertSqlAndParas <PerchaseInStoreInfoModel>(perchaseInfo, cols, 1);
                        cmd.CommandText = inStock.Sql;
                        foreach (var p in inStock.SqlParaArray)
                        {
                            cmd.Parameters.Add(p);
                        }
                        cmd.CommandType = CommandType.Text;
                        object oPerId = cmd.ExecuteScalar();
                        cmd.Parameters.Clear();

                        if (oPerId != null && oPerId.GetInt() > 0)
                        {
                            //入库商品明细保存
                            foreach (PerchaseGoodsInfoModel si in perGoodsList)
                            {
                                si.PerId = oPerId.GetInt();
                                SqlModel inPerGoods = CreateSql.GetInsertSqlAndParas <PerchaseGoodsInfoModel>(si, sgCols, 0);
                                cmd.CommandText = inPerGoods.Sql;
                                cmd.CommandType = CommandType.Text;
                                foreach (var p in inPerGoods.SqlParaArray)
                                {
                                    cmd.Parameters.Add(p);
                                }
                                cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();
                            }
                        }
                        cmd.Transaction.Commit();
                        return oPerId.ToString() + "," + perNo.ToString();
                    }
                    return "";
                }
                catch (Exception ex)
                {
                    cmd.Transaction.Rollback();
                    throw new Exception("执行添加采购单异常!", ex);
                }
            }));
        }
コード例 #23
0
ファイル: PerchaseInStoreDAL.cs プロジェクト: mosdong/PSI
        /// <summary>
        /// 更新采购单信息
        /// </summary>
        /// <param name="perchaseInfo"></param>
        /// <param name="perGoodsList"></param>
        /// <returns></returns>
        public bool UpdatePerchaseInfo(PerchaseInStoreInfoModel perchaseInfo, List <PerchaseGoodsInfoModel> perGoodsList)
        {
            string cols = "UnitId,StoreId,DealPerson,PayDesp,ThisAmount,Remark,TotalAmount,YHAmount,PerId";

            if (perchaseInfo.PayTime != null)
            {
                cols += ",PayTime,IsPayed";
            }
            if (perchaseInfo.IsPayFull == 1)
            {
                cols += ",IsPayFull";
            }
            //插入采购商品列表的列名
            string             pgCols  = "PerId,GoodsId,GUnit,Count,PerPrice,Amount,Remark";
            List <CommandInfo> comList = new List <CommandInfo>();
            SqlModel           upStock = CreateSql.GetUpdateSqlAndParas(perchaseInfo, cols, "");

            //修改采购单信息
            comList.Add(new CommandInfo()
            {
                CommandText = upStock.Sql,
                IsProc      = false,
                Paras       = upStock.SqlParaArray
            });
            //删除已移除的商品明细数据

            //商品明细编号集合字符串
            string goodsIds = string.Join(",", perGoodsList.Select(g => g.GoodsId));

            comList.Add(new CommandInfo()
            {
                CommandText = $"delete from PerchaseGoodsInfos where PerId ={perchaseInfo.PerId} and GoodsId not in ({goodsIds})",
                IsProc      = false
            });

            //明细商品列表保存:修改、添加 两种
            foreach (PerchaseGoodsInfoModel sg in perGoodsList)
            {
                if (pgDAL.ExistsGoods(perchaseInfo.PerId, sg.GoodsId))
                {
                    string         upSql = "update PerchaseGoodsInfos set Count=@count,PerPrice=@perPrice,Amount=@Amount,Remark=@remark where PerId=@perId and GoodsId=@goodsId";
                    SqlParameter[] paras =
                    {
                        new SqlParameter("@perId",    perchaseInfo.PerId),
                        new SqlParameter("@goodsId",  sg.GoodsId),
                        new SqlParameter("@count",    sg.Count),
                        new SqlParameter("@perPrice", sg.PerPrice),
                        new SqlParameter("@remark",   sg.Remark),
                        new SqlParameter("@Amount",   sg.Amount)
                    };
                    comList.Add(new CommandInfo()
                    {
                        CommandText = upSql,
                        IsProc      = false,
                        Paras       = paras
                    });
                }
                else//新增处理
                {
                    sg.PerId = perchaseInfo.PerId;
                    SqlModel inStStockGoods = CreateSql.GetInsertSqlAndParas(sg, pgCols, 0);
                    comList.Add(new CommandInfo()
                    {
                        CommandText = inStStockGoods.Sql,
                        IsProc      = false,
                        Paras       = inStStockGoods.SqlParaArray
                    });
                }
            }
            return(SqlHelper.ExecuteTrans(comList));
        }