Beispiel #1
0
        /// <summary>
        /// 通过ID序号查找顾客状态类型
        /// </summary>
        /// <param name="ID">需要查找的ID序号</param>
        /// <returns>如果返回的ID为-1则为查找失败</returns>
        public static CustStatus FindCustStatusByID(int ID)
        {
            CustStatus node = new CustStatus();

            node.StatusID = -1;

            string str = "select StatusID,StatusName from CustStatus where StatusID = @index";

            SqlParameter[] para = new SqlParameter[] {
                new SqlParameter("@index", SqlDbType.Int)
            };
            para[0].Value = ID;

            SqlDataReader reader = SqlHelper.ExecuteReader(str, para);

            while (reader.Read())
            {
                node.StatusID   = Convert.ToInt32(reader[0]);
                node.StatusName = Convert.ToString(reader[1]);
            }

            reader.Close();

            return(node);
        }
Beispiel #2
0
        /// <summary>
        /// 通过关键字查找顾客状态类型,支持模糊查找
        /// </summary>
        /// <param name="keyword">关键词</param>
        /// <param name="FuzzyMode">模糊查找模式,true为开启,false为关闭</param>
        /// <returns></returns>
        public static List <CustStatus> FindCustStatusByKeyword(string keyword, bool FuzzyMode)
        {
            List <CustStatus> list = new List <CustStatus>();

            string FindStr = "";

            if (FuzzyMode == true)
            {
                FindStr = " like ";
            }
            else
            {
                FindStr = " = ";
            }

            string sqlstr = "select StatusID,StatusName from CustStatus where StatusName" + FindStr + "@searchname";

            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@searchname", SqlDbType.VarChar)
            };

            if (FuzzyMode == true)
            {
                para[0].Value = "%" + keyword + "%";
            }
            else
            {
                para[0].Value = keyword;
            }

            SqlDataReader reader = SqlHelper.ExecuteReader(sqlstr, para);

            while (reader.Read())
            {
                CustStatus node = new CustStatus();
                node.StatusID   = Convert.ToInt32(reader[0]);
                node.StatusName = Convert.ToString(reader[1]);
                list.Add(node);
            }

            reader.Close();

            return(list);
        }
Beispiel #3
0
        /// <summary>
        /// 获取所有顾客状态类型对象
        /// </summary>
        /// <returns></returns>
        public static List <CustStatus> GetAllCustStatus()
        {
            List <CustStatus> list = new List <CustStatus>();

            string        sqlstr = "select StatusID,StatusName from CustStatus";
            SqlDataReader reader = SqlHelper.ExecuteReader(sqlstr);

            while (reader.Read())
            {
                CustStatus node = new CustStatus();
                node.StatusID   = Convert.ToInt32(reader[0]);
                node.StatusName = Convert.ToString(reader[1]);
                list.Add(node);
            }

            reader.Close();

            return(list);
        }
        public void AddCustomerWithDependencies(Customer customer)
        {
            customer.PrimaryAddress.Key = _addressRepository.GetSurrogateKey();
            customer.PrimaryContact.Key = _contactRepository.GetSurrogateKey();
            var custKey = _customerRepository.GetSurrogateKey();

            customer.Key = custKey;

            customer.PrimaryCntctKey = customer.PrimaryContact.Key;
            customer.PrimaryAddrKey  = customer.PrimaryAddress.Key;
            customer.DocTransmittals.ForEach(dt => dt.Key = customer.Key);

            customer.CustAddresses.ForEach(a => a.CustKey = customer.Key);
            customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.Primary).Key          = customer.PrimaryAddress.Key;
            customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.Primary).DfltCntctKey = customer.PrimaryCntctKey;

            if (customer.DefaultBillToAddress != null) //not same as primary
            {
                customer.DefaultBillToAddress.Key = _addressRepository.GetSurrogateKey();
                customer.DfltBillToAddrKey        = customer.DefaultBillToAddress.Key;

                if (customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.BillTo) != null)
                {
                    customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.BillTo).Key        = customer.DefaultBillToAddress.Key;
                    customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.BillTo).CustAddrID = customer.DefaultBillToAddress.Key.ToString();
                }
            }
            else //same as primary
            {
                customer.DefaultBillToAddress = customer.PrimaryAddress;
                customer.DfltBillToAddrKey    = customer.DefaultBillToAddress.Key;
            }

            if (customer.DefaultShipToAddress != null)
            {
                customer.DefaultShipToAddress.Key = _addressRepository.GetSurrogateKey();
                customer.DfltShipToAddrKey        = customer.DefaultShipToAddress.Key;

                if (customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.ShipTo) != null)
                {
                    customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.ShipTo).Key        = customer.DefaultShipToAddress.Key;
                    customer.CustAddresses.Single(a => a.Type == Enums.CustAddrType.ShipTo).CustAddrID = customer.DefaultShipToAddress.Key.ToString();
                }
            }
            else
            {
                customer.DefaultShipToAddress = customer.PrimaryAddress;
                customer.DfltShipToAddrKey    = customer.DefaultShipToAddress.Key;
            }


            var custStatus = new CustStatus
            {
                Key           = customer.Key,
                AgeCat1Amt    = 0,
                AgeCat2Amt    = 0,
                AgeCat3Amt    = 0,
                AgeCat4Amt    = 0,
                AgeCurntAmt   = 0,
                AgeFutureAmt  = 0,
                AvgInvcAmt    = 0,
                FinChgBal     = 0,
                HighestBal    = 0,
                LastStmtAmt   = 0,
                LastStmtAmtNC = 0,
                OnSalesOrdAmt = 0,
                RetntBal      = 0
            };

            customer.CustStatus = custStatus;

            using (var scope = new TransactionScope())
            {
                try
                {
                    _customerRepository.AddCustomerWithDependecies(customer);
                    customer.PrimaryContact.CntctOwnerKey = custKey;
                    _contactRepository.Update(customer.PrimaryContact);

                    scope.Complete();
                }
                catch (Exception)
                {
                    scope.Dispose();

                    throw;
                }
            }
        }