示例#1
0
        /// <summary>
        /// 插入二级库房信息
        /// </summary>
        /// <param name="outStockInfo">数据集</param>
        /// <param name="error">错误信息</param>
        /// <returns>成功返回True,失败返回False</returns>
        public bool InsertInfo(Out_StockInfo outStockInfo, out string error)
        {
            error = null;

            try
            {
                DepotManagementDataContext dataContext = CommentParameter.DepotDataContext;

                var varData = from a in dataContext.Out_StockInfo
                              where a.SecStorageID == outStockInfo.SecStorageID
                              select a;

                if (varData.Count() == 0)
                {
                    dataContext.Out_StockInfo.InsertOnSubmit(outStockInfo);
                    dataContext.SubmitChanges();
                    return(true);
                }
                else
                {
                    error = "数据不唯一";
                    return(false);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
        /// <summary>
        /// 添加客户
        /// </summary>
        /// <param name="clientInfo">客户信息</param>
        /// <param name="returnClient">客户信息结果集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>返回是否成功添加客户信息</returns>
        public bool AddClient(Client clientInfo,
                              out IQueryable <View_Client> returnClient, out string error)
        {
            returnClient = null;
            error        = null;

            DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

            try
            {
                Table <Client> table = dataContxt.GetTable <Client>();

                var varClient = from c in table
                                where c.ClientCode == clientInfo.ClientCode
                                select c;

                int sameNoteCount = varClient.Count <Client>();

                if (sameNoteCount == 0)
                {
                    Table <Out_StockInfo> tableOut = dataContxt.GetTable <Out_StockInfo>();
                    var result = from c in tableOut
                                 where c.SecStorageID == clientInfo.ClientCode
                                 select c;

                    int count = result.Count <Out_StockInfo>();

                    if (count == 0)
                    {
                        if (clientInfo.IsSecStorage)
                        {
                            Out_StockInfo stock = new Out_StockInfo();

                            stock.SecStorageID   = clientInfo.ClientCode;
                            stock.SecStorageName = clientInfo.ClientName;
                            stock.Remark         = clientInfo.Remark;

                            dataContxt.Out_StockInfo.InsertOnSubmit(stock);
                        }
                    }

                    dataContxt.Client.InsertOnSubmit(clientInfo);

                    dataContxt.SubmitChanges();

                    return(GetAllClient(out returnClient, out error));
                }
                else
                {
                    error = "该单据已提交,系统不允许重复提交相同编号的供应商!";
                    return(false);
                }
            }
            catch (Exception err)
            {
                return(SetReturnError(err, out returnClient, out error));
            }
        }
        /// <summary>
        /// 更新客户
        /// </summary>
        /// <param name="clientInfo">客户信息</param>
        /// <param name="oldClient">旧客户信息</param>
        /// <param name="returnClient">客户信息结果集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>返回是否成功更新客户信息</returns>
        public bool UpdateClient(Client clientInfo, Client oldClient,
                                 out IQueryable <View_Client> returnClient, out string error)
        {
            returnClient = null;
            error        = null;

            DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

            try
            {
                if (clientInfo.ClientCode != oldClient.ClientCode)
                {
                    string strSql = "select distinct ObjectDept from (select ObjectDept from S_MarketingBill union all select OutStorageID " +
                                    " from Out_ManeuverBill union all select InStorageID from Out_ManeuverBill) as a where ObjectDept = '" + oldClient.ClientCode + "'";

                    DataTable dtTemp = GlobalObject.DatabaseServer.QueryInfo(strSql);

                    if (dtTemp.Rows.Count > 0)
                    {
                        error = "此编码已存在于业务中不能修改";
                        return(false);
                    }
                }

                Table <Client> table = dataContxt.GetTable <Client>();

                var varClientA = from c in table
                                 where c.ClientCode != oldClient.ClientCode &&
                                 (c.ClientCode == clientInfo.ClientCode || c.ClientName == clientInfo.ClientName)
                                 select c;

                if (varClientA.Count() == 0)
                {
                    var varStockInfoA = from a in dataContxt.Out_StockInfo
                                        where a.SecStorageID != oldClient.ClientCode &&
                                        (a.SecStorageID == clientInfo.ClientCode || a.SecStorageName == clientInfo.ClientName)
                                        select a;

                    if (varStockInfoA.Count() == 0)
                    {
                        if (oldClient.IsSecStorage == clientInfo.IsSecStorage)
                        {
                            if (clientInfo.IsSecStorage)
                            {
                                var varStockInfo = from a in dataContxt.Out_StockInfo
                                                   where a.SecStorageID == oldClient.ClientCode
                                                   select a;

                                foreach (var item in varStockInfo)
                                {
                                    item.SecStorageID   = clientInfo.ClientCode;
                                    item.SecStorageName = clientInfo.ClientName;
                                }
                            }
                        }
                        else
                        {
                            if (clientInfo.IsSecStorage)
                            {
                                Out_StockInfo lnqStock = new Out_StockInfo();

                                lnqStock.SecStorageID   = clientInfo.ClientCode;
                                lnqStock.SecStorageName = clientInfo.ClientName;
                                lnqStock.Remark         = clientInfo.Remark;

                                dataContxt.Out_StockInfo.InsertOnSubmit(lnqStock);
                            }
                            else
                            {
                                var varDel = from a in dataContxt.Out_StockInfo
                                             where a.SecStorageID == oldClient.ClientCode &&
                                             a.SecStorageName == oldClient.ClientName
                                             select a;

                                dataContxt.Out_StockInfo.DeleteAllOnSubmit(varDel);
                            }
                        }

                        var varClient = from c in table
                                        where c.ClientCode == oldClient.ClientCode
                                        select c;

                        foreach (var ei in varClient)
                        {
                            ei.ClientName   = clientInfo.ClientName;
                            ei.Remark       = clientInfo.Remark;
                            ei.Address      = clientInfo.Address;
                            ei.Linkman      = clientInfo.Linkman;
                            ei.Phone        = clientInfo.Phone;
                            ei.Principal    = clientInfo.Principal;
                            ei.Province     = clientInfo.Province;
                            ei.ServiceArea  = clientInfo.ServiceArea;
                            ei.IsSecStorage = clientInfo.IsSecStorage;
                            ei.AllName      = clientInfo.AllName;
                        }

                        dataContxt.SubmitChanges();
                    }
                    else
                    {
                        error = "二级库房编码或名称重复";
                        return(false);
                    }
                }
                else
                {
                    error = "编码或名称重复";
                    return(false);
                }

                return(GetAllClient(out returnClient, out error));
            }
            catch (Exception err)
            {
                return(SetReturnError(err, out returnClient, out error));
            }
        }
示例#4
0
        /// <summary>
        /// 修改库房信息
        /// </summary>
        /// <param name="oldStorageID">库房旧编码</param>
        /// <param name="outStockInfo">库房数据集</param>
        /// <param name="error">错误信息</param>
        /// <returns>成功返回True,失败返回False</returns>
        public bool ModifyInfo(string oldStorageID, Out_StockInfo outStockInfo, out string error)
        {
            error = null;

            try
            {
                DepotManagementDataContext dataContext = CommentParameter.DepotDataContext;

                var varData = from a in dataContext.Out_StockInfo
                              where a.SecStorageID == oldStorageID
                              select a;

                if (varData.Count() == 1)
                {
                    if (oldStorageID != outStockInfo.SecStorageID)
                    {
                        if (oldStorageID != outStockInfo.SecStorageID)
                        {
                            var varStockInfo = from c in dataContext.Out_StockInfo
                                               where c.SecStorageID == outStockInfo.SecStorageID
                                               select c;

                            if (varStockInfo.Count() > 0)
                            {
                                error = "此编码已存在,库房编码不能重复";
                                return(false);
                            }
                        }

                        var varDetailData = from b in dataContext.Out_DetailAccount
                                            where b.SecStorageID == oldStorageID
                                            select b;

                        if (varDetailData.Count() > 0)
                        {
                            error = "此库房旧编码已在业务数据中存在,不能修改此库房的编码或者所属库房";
                            return(false);
                        }
                    }

                    Out_StockInfo lnqStockInfo = varData.Single();

                    lnqStockInfo.Remark         = outStockInfo.Remark;
                    lnqStockInfo.SecStorageID   = outStockInfo.SecStorageID;
                    lnqStockInfo.SecStorageName = outStockInfo.SecStorageName;

                    dataContext.SubmitChanges();

                    return(true);
                }
                else
                {
                    error = "数据不唯一";
                    return(false);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }