Example #1
0
        public ActionResult GenJsonResult(string contactid)
        {
            ViewData["contactid"] = contactid;
            if (contactid == null)
            {
                return(View());// Json(emptyobj, JsonRequestBehavior.AllowGet);
            }
            repoCustomer.UnitOfWork.Context.Configuration.LazyLoadingEnabled = false;
            repoCustType.UnitOfWork.Context.Configuration.LazyLoadingEnabled = false;
            repoContact.UnitOfWork.Context.Configuration.LazyLoadingEnabled  = false;
            repoBank.UnitOfWork.Context.Configuration.LazyLoadingEnabled     = false;
            int strid = int.Parse(contactid);

            客戶資料Entities db = new 客戶資料Entities();

            db.Configuration.LazyLoadingEnabled = false;
            var data = db.客戶聯絡人.FirstOrDefault(p => p.Id == strid);

            //var data = repoContact.Find(strid);
            if (data == null)
            {
                var emptyobj = new { id = contactid, description = "不存在的客戶聯絡人" };
                return(Json(emptyobj, JsonRequestBehavior.AllowGet));
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        /// <summary> 客戶資料檢視表 </summary>
        /// <returns></returns>
        public ActionResult CustomerDetails()
        {
            客戶資料Entities db      = new 客戶資料Entities();
            var          客戶資料檢視表 = db.CustomerDetailsView;

            return(View(客戶資料檢視表));
        }
        protected JArray GetExportDataWithAllColumns_Statistics()
        {
            var db     = new 客戶資料Entities();
            var result = db.客戶資料.Where(P => P.是否已刪除 != true);

            // LINQ ( C# 3.0 )
            //var data = "SELECT * FROM table WHERE ...";
            var data = from p in result
                       select new 客戶統計()
            {
                客戶名稱   = p.客戶名稱,
                銀行帳戶數量 = p.客戶銀行資訊.Count(),
                聯絡人數量  = p.客戶聯絡人.Count()
            };

            JArray jObjects = new JArray();

            foreach (var item in data)
            {
                var jo = new JObject
                {
                    { "客戶名稱", item.客戶名稱 },
                    { "聯絡人數量", item.聯絡人數量 },
                    { "銀行帳戶數量", item.銀行帳戶數量 }
                };
                jObjects.Add(jo);
            }
            return(jObjects);
        }
Example #4
0
 public ActionResult SearchByName(string CustomerName)
 {
     using (Models.客戶資料Entities db = new 客戶資料Entities())
     {
         var result = (from s in db.客戶銀行資訊.Include(s => s.客戶資料)
                       where s.客戶資料.客戶名稱.Contains(CustomerName) && s.is刪除 == false
                       select s).ToList();
         return(View("Index", result));
     }
 }
Example #5
0
 public static void RemoveAll()
 {
     using (var context = new 客戶資料Entities())
     {
         context.客戶銀行資訊.RemoveRange(context.客戶銀行資訊);
         context.客戶聯絡人.RemoveRange(context.客戶聯絡人);
         context.客戶資料.RemoveRange(context.客戶資料);
         context.SaveChanges();
     }
 }
Example #6
0
        public bool isRepeatedEmail(客戶聯絡人 l_person)
        {
            客戶資料Entities db = new 客戶資料Entities();

            if (l_person.Id != 0)
            {
                return(true);
            }
            var l_data = db.客戶聯絡人.Where(a => a.客戶Id == l_person.客戶Id && a.Email == l_person.Email).ToList();

            return(l_data.Count == 0);
        }
Example #7
0
        public ActionResult SearchByCustomerContactName(string ContactName)
        {
            //var 客戶聯絡人 = db.客戶聯絡人.Include(客 => 客.客戶資料);
            //return View(客戶聯絡人.ToList());

            using (Models.客戶資料Entities db = new 客戶資料Entities())
            {
                var result = (from s in db.客戶聯絡人.Include(s => s.客戶資料)
                              where s.姓名.Contains(ContactName) && s.is刪除 == false
                              select s).ToList();
                return(View("Index", result));
            }
        }
        protected object getStatistics()
        {
            var db     = new 客戶資料Entities();
            var result = db.客戶資料.Where(P => P.是否已刪除 != true);

            // LINQ ( C# 3.0 )
            //var data = "SELECT * FROM table WHERE ...";
            var data = from p in result
                       select new 客戶統計()
            {
                客戶名稱   = p.客戶名稱,
                銀行帳戶數量 = p.客戶銀行資訊.Count(),
                聯絡人數量  = p.客戶聯絡人.Count()
            };

            return(data);
        }
Example #9
0
        public static void Init()
        {
            using (var context = new 客戶資料Entities())
            {
                if (!context.客戶資料.Any(customer => !customer.已刪除))
                {
                    var customers = Random客戶資料(50).ToArray();
                    var blanks    = customers.SelectMany(c => Random銀行資訊(random.Next(1, 10), c.客戶名稱, c.Id)).ToArray();
                    var concats   = customers.SelectMany(c => Random客戶聯絡人(random.Next(1, 10), c.客戶名稱, c.Id)).ToArray();

                    context.客戶資料.AddOrUpdate(customers);
                    context.客戶聯絡人.AddOrUpdate(concats);
                    context.客戶銀行資訊.AddOrUpdate(blanks);
                    context.SaveChanges();
                }
            }
        }
Example #10
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            using (客戶資料Entities db = new 客戶資料Entities())
            {
                var contact  = (客戶聯絡人)validationContext.ObjectInstance;
                var customer = db.客戶資料.Where(c => c.Id == contact.客戶Id && !c.是否已刪除).FirstOrDefault();

                if (customer == null)
                {
                    yield return(new ValidationResult("該客戶不存在!"));
                }

                if (customer.客戶聯絡人.Any(c => c.Email == this.Email.ToString().Trim() && c.Id != contact.Id))
                {
                    yield return(new ValidationResult(string.Format("{0}下已存在 Email 為 {1} 的聯絡人,請另外使用別的 Email!", customer.客戶名稱, this.Email)));
                }
            }
        }
        protected object dataStoSort_Statistics(int?id)
        {
            var db     = new 客戶資料Entities();
            var result = db.客戶資料.Where(P => P.是否已刪除 != true);

            // LINQ ( C# 3.0 )
            //var data = "SELECT * FROM table WHERE ...";
            var data = from p in result
                       select new 客戶統計()
            {
                客戶名稱   = p.客戶名稱,
                銀行帳戶數量 = p.客戶銀行資訊.Count(),
                聯絡人數量  = p.客戶聯絡人.Count()
            };

            switch (id)
            {
            case 1:
                data = data.OrderBy(P => P.客戶名稱);
                break;

            case 2:
                data = data.OrderBy(P => P.聯絡人數量);
                break;

            case 3:
                data = data.OrderBy(P => P.銀行帳戶數量);
                break;

            case 11:
                data = data.OrderByDescending(P => P.客戶名稱);
                break;

            case 22:
                data = data.OrderByDescending(P => P.聯絡人數量);
                break;

            case 33:
                data = data.OrderByDescending(P => P.銀行帳戶數量);
                break;
            }

            return(data);
        }
Example #12
0
 public EFUnitOfWork()
 {
     Context = new 客戶資料Entities();
 }