Exemplo n.º 1
0
 public CrmSpecialDiscBill GetRuleBill(int billId)
 {
     lock (billList)
     {
         foreach (CrmSpecialDiscBill bill in billList)
         {
             if (bill.BillId == billId)
             {
                 return(bill);
             }
         }
         CrmSpecialDiscBill bill2 = CreateRuleBill(billId);
         if (bill2 != null)
         {
             billList.Add(bill2);
         }
         return(bill2);
     }
 }
Exemplo n.º 2
0
        private CrmSpecialDiscBill CreateRuleBill(int billId)
        {
            CrmSpecialDiscBill bill = null;
            DbConnection       conn = DbConnManager.GetDbConnection("CRMDB");
            DbCommand          cmd  = conn.CreateCommand();
            StringBuilder      sql  = new StringBuilder();

            try
            {
                try
                {
                    conn.Open();
                }
                catch (Exception e)
                {
                    throw new MyDbException(e.Message, true);
                }
                try
                {
                    sql.Append("select KSRQ,JSRQ from HYTDJFDYD where JLBH = ").Append(billId);
                    cmd.CommandText = sql.ToString();
                    DbDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        bill           = new CrmSpecialDiscBill();
                        bill.BillId    = billId;
                        bill.BeginTime = DbUtils.GetDateTime(reader, 0);
                        bill.EndTime   = DbUtils.GetDateTime(reader, 1);
                        reader.Close();

                        sql.Length = 0;
                        sql.Append("select GZBH,JFBS,BSFS,GRPID from HYTDJFDYD_GZSD where JLBH = ").Append(billId);
                        sql.Append(" order by GZBH");
                        cmd.CommandText = sql.ToString();
                        reader          = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            if (bill.Items == null)
                            {
                                bill.Items = new List <CrmSpecialDiscBillItem>();
                            }
                            CrmSpecialDiscBillItem item = new CrmSpecialDiscBillItem();
                            bill.Items.Add(item);
                            item.Inx                 = DbUtils.GetInt(reader, 0);
                            item.DiscRate            = DbUtils.GetDouble(reader, 1);
                            item.DiscCombinationMode = DbUtils.GetInt(reader, 2);
                            item.VipGroup.GroupId    = DbUtils.GetInt(reader, 3);
                        }
                        reader.Close();

                        if (bill.Items != null)
                        {
                            foreach (CrmSpecialDiscBillItem item in bill.Items)
                            {
                                if (item.VipGroup.GroupId > 0)
                                {
                                    CrmPubUtils.GetVipGroup(cmd, sql, item.VipGroup);
                                }
                            }
                        }
                        return(bill);
                    }
                    else
                    {
                        reader.Close();
                    }
                }
                catch (Exception e)
                {
                    if (e is MyDbException)
                    {
                        throw e;
                    }
                    else
                    {
                        throw new MyDbException(e.Message, cmd.CommandText);
                    }
                }
            }
            finally
            {
                conn.Close();
            }
            return(null);
        }