예제 #1
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            CanClose = false;

            using (var SSEntity = new SmartShoppingEntities())
            {
                var q = (from u in SSEntity.SSUsers
                         where u.Employee_ID == this.txtEmployeeID.Text && u.Password == this.txtPassword.Text
                         select new { u.Employee_ID, EmployeeName = u.EmployeeName }).FirstOrDefault();
                if (q == null)
                {
                    MessageBox.Show("登入帳號或密碼錯誤!", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    frmMain.FAllowCheck = false;
                    Logincount++;
                    if (Logincount == 3)
                    {
                        MessageBox.Show("登入錯誤已達3次!", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        CanClose = true;
                    }
                }
                else
                {
                    frmMain.FAllowCheck = true;
                    frmMain.FUserID     = q.Employee_ID;
                    frmMain.FUserName   = q.EmployeeName;
                    CanClose            = true;
                }
            }
        }
예제 #2
0
        private void LoadAdLabel()
        {
            this.flowLayoutPanel1.Controls.Clear();
            using (SmartShoppingEntities db = new SmartShoppingEntities())
            {
                var q = from p in db.Promotions
                        where p.AdHtml != null
                        select p;

                foreach (var item in q)
                {
                    LinkLabel lb = new LinkLabel();
                    lb.Text = item.PromotionName;

                    Dictionary <int, string> atag = new Dictionary <int, string>();
                    atag.Add(item.Promotion_ID, item.AdHtml);
                    lb.Tag      = atag;
                    lb.AutoSize = true;
                    lb.Margin   = new Padding(0, 0, 0, 10);
                    //
                    this.flowLayoutPanel1.Controls.Add(lb);

                    lb.Click += lb_Click;
                }
            }
        }
예제 #3
0
        //private List<MyRelateProduct> GetRelateProductTop5v2(string p)
        //{

        //}



        //private void button1_Click(object sender, EventArgs e)
        //{
        //    List<int> members = new List<int>();
        //    using (SqlConnection conn = new SqlConnection(Settings.Default.SmartShoppingConnectionString))
        //    {
        //        using (SqlCommand cmd = new SqlCommand("getrelateproduct", conn))
        //        {

        //            cmd.CommandType = System.Data.CommandType.StoredProcedure;
        //            cmd.Parameters.AddWithValue("@pid", 1);//write for loop till no products
        //            conn.Open();
        //            SqlDataReader dr = cmd.ExecuteReader();
        //            while (dr.Read())
        //            {
        //                members.Add((int)dr[0]);
        //            }
        //            conn.Close();

        //        }
        //        string memberstr="";
        //        for (int i = 0; i < members.Count; i++)
        //    {
        //        if (i < members.Count - 1)
        //        {
        //            memberstr += members[i].ToString() + ",";
        //        }
        //        else
        //        {
        //            memberstr += members[i].ToString();
        //        }

        //    }

        //        using (SqlCommand cmd = new SqlCommand("getbestrelate", conn))
        //        {
        //            cmd.CommandType = System.Data.CommandType.StoredProcedure;
        //            //write for loop till no members. put all products in a list and count
        //            cmd.Parameters.AddWithValue("@mid", "");//cant use string, must use int one by one
        //            conn.Open();
        //            SqlDataReader dr = cmd.ExecuteReader();
        //            while (dr.Read())
        //            {
        //                listBox1.Items.Add(dr["Product_ID"].ToString());
        //            }
        //            conn.Close();
        //        }
        //    }
        //}

        ////int First = 0;
        ////int Second = 0;
        ////int Third = 0;
        ////int Fourth = 0;
        ////below way give you a count of each item in the List...still too stupid!
        //private void button2_Click(object sender, EventArgs e)
        //{
        //    List<int> countProduct = new List<int>();
        //    countProduct.Add(1);
        //    countProduct.Add(2);
        //    countProduct.Add(2);
        //    countProduct.Add(2);
        //    for (int i = 0; i < countProduct.Count(); i++)
        //    {
        //        this.listBox1.Items.Add(countProduct[i] + "(" + countProduct.Count(j => j.Equals(countProduct[i])) + ")");
        //    }


        //}

        private void button3_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 0;

            button4_Click(sender, e);

            SmartShoppingEntities SSE = new SmartShoppingEntities();
            var q = from o in SSE.Orders
                    select o.Order_ID;//目前所有的order
            var list = q.ToList();

            for (int i = 0; i < list.Count; i++)
            {
                List <int> Products = GetProductID(list[i]);//由orderID 拿到該單的產品ID List
                AddToRelationTable(Products);
            }//加進table裡面

            //顯現出來

            // TODO:  這行程式碼會將資料載入 'smartShoppingDataSet.ReportTable' 資料表。您可以視需要進行移動或移除。
            this.ReportTableTableAdapter.FillByPID(this.smartShoppingDataSet.ReportTable, 1);
            // TODO:  這行程式碼會將資料載入 'smartShoppingDataSet1.DataTable1' 資料表。您可以視需要進行移動或移除。
            this.dataTable1TableAdapter.Fill(this.smartShoppingDataSet1.DataTable1);
            // TODO:  這行程式碼會將資料載入 'smartShoppingDataSet.View_ProductxMember' 資料表。您可以視需要進行移動或移除。


            this.reportViewer1.RefreshReport();

            this.reportViewer2.RefreshReport();
        }
예제 #4
0
        private void SearchProducts()
        {
            if (SearchTextBox.Text == String.Empty)
            {
                //查詢資料為空字串,取得所有的廠商記錄
                GetAllProducts();
            }
            else
            {
                switch (SearchByComboBox.SelectedIndex)
                {
                case 0:
                    //依商品編號查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得商品資料表商品編號條件的記錄
                        var qry = from p in context.Products
                                  where p.Product_ID.ToString() == SearchTextBox.Text
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        productBindingSource.DataSource = qry.ToList();
                    }
                    break;

                case 1:
                    //依商品名稱查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得商品資料符合商品名稱條件的記錄
                        var qry = from p in context.Products
                                  where p.ProductName.Contains(SearchTextBox.Text)
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        productBindingSource.DataSource = qry.ToList();
                    }
                    break;

                case 2:
                    //依商品分類查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得商品資料符合商品名稱分類條件的記錄
                        var ID = from p in context.Categories
                                 where p.CategoryName == SearchTextBox.Text
                                 select p.Category_ID;

                        var qry = from p in context.Products
                                  where p.Category_ID == ID.First()
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        productBindingSource.DataSource = qry.ToList();
                    }
                    break;
                }
            }
        }
예제 #5
0
        private void SyncADMINSSAuthority()
        {
            using (var SSEntities = new SmartShoppingEntities())
            {
                try
                {
                    //確定系統管理者擁有全部程式的權限
                    string ADMIN = "ADMIN";

                    //系統管理者ADMIN是否存在
                    var ADMINqry = (from E in SSEntities.SSUsers
                                    where E.Employee_ID == ADMIN
                                    select E).FirstOrDefault();

                    if (ADMINqry == null)
                    {
                        //新增系統管理者ADMIN
                        SSUsers NewSSUsers = new SSUsers();
                        NewSSUsers.Employee_ID  = ADMIN;
                        NewSSUsers.EmployeeName = "系統管理員";
                        NewSSUsers.Password     = ADMIN;
                        SSEntities.SSUsers.Add(NewSSUsers);
                        //更新資料
                        SSEntities.SaveChanges();
                    }

                    //找出全部的程式
                    var qryPrograms = from P in SSEntities.SSPrograms
                                      select P.Program_ID;

                    foreach (var P in qryPrograms)
                    {
                        //系統管理者的使用權限是否存在
                        var qry = (from A in SSEntities.SSAuthority
                                   where A.Employee_ID == ADMIN && A.Program_ID == P
                                   select A).FirstOrDefault();
                        if (qry == null)
                        {
                            //新增系統管理者的使用權限
                            SSAuthority NewAuthority = new SSAuthority();
                            NewAuthority.Employee_ID = ADMIN;
                            NewAuthority.Program_ID  = P;
                            NewAuthority.Run         = true;
                            NewAuthority.Edit        = true;
                            SSEntities.SSAuthority.Add(NewAuthority);
                        }
                    }
                    //更新資料
                    SSEntities.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #6
0
        private void SearchProducts()
        {
            if (SearchTextBox.Text == String.Empty)
            {
                //查詢資料為空字串,取得所有的廠商記錄
                GetAllMembers();
            }
            else
            {
                switch (SearchByComboBox.SelectedIndex)
                {
                case 0:
                    //依會員編號查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得客戶資料表符合會員編號條件的記錄
                        var qry = from p in context.Members
                                  where p.Member_ID.ToString() == SearchTextBox.Text
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        MembersBindingSource.DataSource = qry.ToList();
                    }
                    break;

                case 1:
                    //依會員姓名查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        ////取得客戶資料表符合會員姓名條件的記錄
                        var qry = from p in context.Members
                                  where p.MemberName.Contains(SearchTextBox.Text)
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        MembersBindingSource.DataSource = qry.ToList();
                    }
                    break;

                case 2:
                    //依會員帳號查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得客戶資料表符合會員帳號條件的記錄
                        var qry = from p in context.Members
                                  where p.Username.Contains(SearchTextBox.Text)
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        MembersBindingSource.DataSource = qry.ToList();
                    }
                    break;
                }
            }
        }
예제 #7
0
        private void SearchVendors()
        {
            if (SearchTextBox.Text == String.Empty)
            {
                //查詢資料為空字串,取得所有的廠商記錄
                GetAllVendors();
            }
            else
            {
                switch (SearchByComboBox.SelectedIndex)
                {
                case 0:
                    //依廠商編號查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得廠商資料表符合廠商編號條件的記錄
                        var qry = from p in context.Vendors
                                  where p.Vendor_ID.ToString() == SearchTextBox.Text
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        VendorsBindingSource.DataSource = qry.ToList();
                    }
                    break;

                case 1:
                    //依廠商名稱查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得廠商資料表符合廠商名稱條件的記錄
                        var qry = from p in context.Vendors
                                  where p.VendorName.Contains(SearchTextBox.Text)
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        VendorsBindingSource.DataSource = qry.ToList();
                    }
                    break;

                case 2:
                    //依統一編號查詢
                    using (var context = new SmartShoppingEntities())
                    {
                        //取得廠商資料表符合統一編號條件的記錄
                        var qry = from p in context.Vendors
                                  where p.UnifiedBusinessNumber == SearchTextBox.Text
                                  select p;

                        //將取得的結果指派給BindingSource控制項的DataSource
                        VendorsBindingSource.DataSource = qry.ToList();
                    }
                    break;
                }
            }
        }
예제 #8
0
        private void GetAllProducts()
        {
            using (var context = new SmartShoppingEntities())
            {
                //取得廠商資料表所有的記錄
                var qry = from p in context.Products select p;
                Debug.WriteLine(qry.ToString());

                //將取得的結果指派給BindingSource控制項的DataSource
                productBindingSource.DataSource = qry.ToList();
            }
        }
예제 #9
0
        private void GetAllVendors()
        {
            using (var context = new SmartShoppingEntities())
            {
                //取得廠商資料表所有的記錄
                //var qry = context.Vendors.Execute(MergeOption.OverwriteChanges);
                var qry = from p in context.Vendors select p;
                Debug.WriteLine(qry.ToString());

                //將取得的結果指派給BindingSource控制項的DataSource
                //VendorsBindingSource.DataSource = qry;
                VendorsBindingSource.DataSource = qry.ToList();
            }
        }
예제 #10
0
        private void CreateTable()//把今天要發送的所有通知存進insideEmailList
        {
            this.insideEmailListTableAdapter1.DeleteQuery();
            string date = this.textBox1.Text;
            int    setDateBefore;

            if (int.TryParse(date, out setDateBefore))
            {
            }
            else
            {
                MessageBox.Show("提醒時間設置錯誤");

                return;
            }

            using (SmartShoppingEntities SSE = new SmartShoppingEntities())
            {
                deliverydate = DateTime.Today.AddDays(setDateBefore);

                var q = from o in SSE.Orders
                        where o.ArrivalDate == deliverydate
                        select o;//所有今天該提醒的單
                count = q.Count();
                foreach (var item in q)
                {
                    int memberid = (int)item.Member_ID;


                    var member = (from m in SSE.Members
                                  where m.Member_ID == item.Member_ID && m.AdOK == true
                                  select new { getEmail = m.Email, memberName = m.MemberName, memberTel = m.MobilePhone }).FirstOrDefault();//每一張單抓到該提醒的會員的email



                    var getProductName = from o in SSE.OrderDetail
                                         where o.Order_ID == item.Order_ID
                                         select o;//抓到所有商品名稱 數量

                    foreach (var od in getProductName)
                    {
                        string productName = od.Products.ProductName; //每次抓到一個商品
                        int    quantity    = (int)od.Quantity;        //抓到一個數量
                        //寫到資料庫
                        this.insideEmailListTableAdapter1.InsertQuery(memberid, member.memberName, member.getEmail, productName, deliverydate, quantity, false, member.memberTel);
                        //目前都由這動作負責create sending table
                    }
                }
            }
        }
예제 #11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //開始密碼變更,禁止關閉視窗
            CanClose = false;

            //驗證程序
            try
            {
                if (NewPasswordTextBox.Text == "")
                {
                    MessageBox.Show("新密碼不可空白!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NewPasswordTextBox.Focus();
                    return;
                }
                if (NewPasswordTextBox.Text != ConfirmPasswordTextBox.Text)
                {
                    MessageBox.Show("新密碼與確認密碼不一致!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NewPasswordTextBox.Focus();
                    return;
                }
                using (var SSEntities = new SmartShoppingEntities())
                {
                    var qry = (from U in SSEntities.SSUsers
                               where U.Employee_ID == frmMain.FUserID && U.Password == OrignalPasswordTextBox.Text
                               select U).FirstOrDefault();
                    if (qry == null)
                    {
                        MessageBox.Show("原來密碼錯誤!", "錯誤",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        OrignalPasswordTextBox.Focus();
                        return;
                    }

                    //開始更新使用者的密碼
                    qry.Password = NewPasswordTextBox.Text;
                    SSEntities.SaveChanges();
                    MessageBox.Show("密碼變更完成,下次登入請使用新密碼", "變更密碼", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //完成密碼變更,允許關閉視窗
            CanClose = true;
        }
예제 #12
0
        //檢查指定程式是否有執行權限
        private bool CheckProgramRight(int ProgramID)
        {
            var blnRun = false;

            //檢查指定的程式是否有執行權限
            using (var SSEntities = new SmartShoppingEntities())
            {
                var qryAuth = (from M in SSEntities.SSAuthority
                               where M.Employee_ID == FUserID && M.Program_ID == ProgramID
                               select M).FirstOrDefault();
                if (qryAuth != null)
                {
                    blnRun = Convert.ToBoolean(qryAuth.Run);
                }
            }
            return(blnRun);
        }
예제 #13
0
        //同步全部程式
        private void SyncProgram()
        {
            using (var SSEntities = new SmartShoppingEntities())
            {
                try
                {
                    string ProgramName = "";

                    //取得目前的組件
                    Assembly thisAssembly = Assembly.GetExecutingAssembly();
                    //取得組件內所有類別型態
                    foreach (var t in thisAssembly.GetTypes())
                    {
                        //如果父類別是繼承自Form的話
                        if (t.IsSubclassOf(typeof(Form)))
                        {
                            //列出該類別資訊
                            ProgramName = t.Name.ToString();

                            //檢查程式代碼資料表是否有此程式代碼的記錄
                            var qry = (from P in SSEntities.SSPrograms
                                       where P.ProgramName == ProgramName
                                       select P).FirstOrDefault();

                            int MaxID = SSEntities.SSPrograms.Max(i => i.Program_ID);
                            if (qry == null)
                            {
                                //新增程式代碼記錄
                                var NewProgram = new SSPrograms();
                                NewProgram.Program_ID  = MaxID + 1;
                                NewProgram.ProgramName = ProgramName;

                                //加入程式代碼
                                SSEntities.SSPrograms.Add(NewProgram);
                                //更新資料
                                SSEntities.SaveChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #14
0
        public string CheckProductIDandGetProductName(string productID, bool CheckDiscontinue = false)
        {
            bool   FCheck       = false;
            bool   Discontinued = false;
            string ProductName  = "";

            using (var SSEntities = new SmartShoppingEntities())
            {
                var q = (from p in SSEntities.Products
                         where p.Product_ID.ToString() == productID
                         select new { p.Product_ID, p.Discontinued, p.ProductName }).FirstOrDefault();
                if (q != null)
                {
                    FCheck       = true;
                    Discontinued = q.Discontinued;
                    ProductName  = q.ProductName;
                }
            }
            if (!FCheck)
            {
                if (productID == null)
                {
                    MessageBox.Show("請輸入要查詢的商品", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("找不到商品", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (CheckDiscontinue && Discontinued)
                {
                    MessageBox.Show("此為停售商品", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (FCheck)
            {
                return(ProductName);
            }
            else
            {
                return("無此商品");
            }
        }
예제 #15
0
        private void SaveToDB()
        {
            SmartShoppingEntities SSE = new SmartShoppingEntities();

            //清空
            SSE.Database.ExecuteSqlCommand("TRUNCATE TABLE [RecommendationChart]");

            var q = from p in SSE.Products
                    select p.Product_ID;//目前所有的order
            var list = q.ToList();

            for (int i = 0; i < list.Count; i++)//每一個PID
            {
                int    PID = list[i];
                string p   = "P" + PID.ToString();
                List <MyRelateProduct> Products = GetRelateProductTop5(p);//PID一個一個進查詢
                for (int k = 0; k < Products.Count; k++)
                {
                    using (SqlConnection conn = new SqlConnection(Settings.Default.SmartShoppingConnectionString))
                    {
                        string commStr = "insert into RecommendationChart (PID, NO, Score, NOName) values (@PID, @NO, @Score, @NOName)";

                        using (SqlCommand cmd = new SqlCommand(commStr, conn))
                        {
                            conn.Open();
                            cmd.Parameters.AddWithValue("@PID", PID);

                            cmd.Parameters.AddWithValue("@NO", Products[k].PID);
                            cmd.Parameters.AddWithValue("@Score", Products[k].Score);
                            cmd.Parameters.AddWithValue("@NOName", Products[k].ProductName);



                            cmd.ExecuteNonQuery();

                            conn.Close();
                        }
                    }
                }
            }
            //存好了顯示出來
        }
예제 #16
0
 private void button3_Click(object sender, EventArgs e)
 {
     AdHTML = htmlEditorControl1.InnerHtml;
     //using (EditHtmlForm dialog = new EditHtmlForm())
     //{
     //    dialog.HTML = this.DocumentHtml;
     //    dialog.ReadOnly = true;
     //    dialog.SetCaption(HTML_TITLE_VIEW);
     //    DefineDialogProperties(dialog);
     //    dialog.ShowDialog(this.ParentForm);
     //}
     //寫進資料庫
     using (SmartShoppingEntities db = new SmartShoppingEntities())
     {
         //新增
         if (NewAd)
         {
             Promotions promotion = new Promotions();
             promotion.AdHtml          = AdHTML;
             promotion.PromotionName   = this.textBoxTitle.Text;
             db.Entry(promotion).State = EntityState.Added;
         }
         else
         {
             //修改
             Promotions promotion = db.Promotions.Find(AdID);
             promotion.AdHtml          = AdHTML;
             promotion.PromotionName   = this.textBoxTitle.Text;
             db.Entry(promotion).State = EntityState.Modified;
         }
         try
         {
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     LoadAdLabel();
     MessageBox.Show("儲存成功");
 }
예제 #17
0
        //同步全部使用者權限(系統管理者擁有全部程式的權限,其他使用者至少要有更改自己密碼的權限)
        private void SyncBaceSSAuthority()
        {
            using (var SSEntities = new SmartShoppingEntities())
            {
                try
                {
                    //其他使用者至少要有更改自己密碼的權限
                    string EmployeeID;

                    //找出全部的使用者
                    var qrysUsers = from E in SSEntities.SSUsers select E.Employee_ID;

                    foreach (var U in qrysUsers)
                    {
                        EmployeeID = (string)U;
                        var qry = (from A in SSEntities.SSAuthority
                                   where A.Employee_ID == EmployeeID
                                   select A).FirstOrDefault();
                        if (qry == null)
                        {
                            var ProgramUserPassword = (SSEntities.SSPrograms.Where(i => i.ProgramName == "frmUserPassword")).FirstOrDefault();

                            //新增使用權限記錄
                            SSAuthority NewAuthority = new SSAuthority();
                            NewAuthority.Employee_ID = EmployeeID;
                            NewAuthority.Program_ID  = ProgramUserPassword.Program_ID;
                            NewAuthority.Run         = true;
                            NewAuthority.Edit        = true;
                            SSEntities.SSAuthority.Add(NewAuthority);
                        }
                    }
                    //更新資料
                    SSEntities.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #18
0
        private void FromOrderToSmart()
        {
            using (SmartShoppingEntities db = new SmartShoppingEntities())
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE [RoleSmart]");

                var q = from r in db.View_RoleXProduct
                        select r;//只從新增的開始讀?上次讀到幾要存起來
                foreach (var item in q.ToList())
                {
                    //檢查RoleSmart資料表是否有此Role X Product的紀錄
                    var qry = (from P in db.RoleSmart
                               where P.RoleID == item.Roles_ID && P.ProductID == item.Product_ID
                               select P).FirstOrDefault();
                    if (qry == null)
                    {
                        //新增程式代碼記錄
                        var NewRS = new RoleSmart();
                        NewRS.RoleID         = item.Roles_ID;
                        NewRS.ProductID      = item.Product_ID;
                        NewRS.TimesPurchased = 1;
                        NewRS.OrderBilling   = item.Amount;


                        //加入程式代碼
                        db.Entry(NewRS).State = EntityState.Added;
                        db.SaveChanges();
                    }
                    else
                    {
                        RoleSmart rs = db.RoleSmart.Find(item.Roles_ID, item.Product_ID);
                        rs.TimesPurchased += 1;
                        rs.OrderBilling   += item.Amount;
                        db.Entry(rs).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
        }
예제 #19
0
 //設定全部程式是否可以執行
 private void SyncProgramsRight()
 {
     using (var SSEntities = new SmartShoppingEntities())
     {
         try
         {
             int sProgramID;
             //從MenuStrip1控制項集合找出每一個控制項
             foreach (var tsmi in menuStrip1.Items)
             {
                 if (!(tsmi is ToolStripItem))
                 {
                     continue;
                 }
                 //找出MenuStrip1.Items的子控制項
                 foreach (var SubItem in
                          ((ToolStripMenuItem)(tsmi)).DropDownItems)
                 {
                     //判斷找出的控制項是否為ToolStripMenuItem類別
                     if (SubItem is ToolStripMenuItem)
                     {
                         sProgramID = (int)((ToolStripMenuItem)SubItem).Tag;
                         //取得是否有執行程式的權限
                         ((ToolStripMenuItem)SubItem).Enabled = CheckProgramRight(sProgramID);
                     }
                     else
                     {
                         continue;
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
예제 #20
0
        private void button4_Click(object sender, EventArgs e)
        {
            //清空資料表 把顯示狀態改一下
            this.tabControl1.SelectedIndex = 0;

            using (SqlConnection conn = new SqlConnection(Settings.Default.SmartShoppingConnectionString))
            {
                string commStr = "Delete from Recommendation";

                using (SqlCommand cmd = new SqlCommand(commStr, conn))
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                //把產品有幾個長出來
                SmartShoppingEntities SSE = new SmartShoppingEntities();
                var q = from p in SSE.Products
                        select p.Product_ID;
                var    list     = q.ToList();
                string allother = "";
                string zeros    = "";
                for (int i = 1; i <= list.Count; i++)
                {
                    if (i < list.Count)
                    {
                        allother += string.Format("P{0}", i) + ",";
                        zeros    += "0,";
                    }
                    else
                    {
                        allother += string.Format("P{0}", i);
                        zeros    += "0";
                    }
                }
                for (int i = 0; i < list.Count; i++)
                {
                    string commStr2 = "insert into Recommendation (PID, " + allother + ") values (" + list[i] + "," + zeros + ")";
                    //all "0" 還沒寫

                    using (SqlCommand cmd = new SqlCommand(commStr2, conn))
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
            }

            // TODO:  這行程式碼會將資料載入 'smartShoppingDataSet.ReportTable' 資料表。您可以視需要進行移動或移除。
            this.ReportTableTableAdapter.Fill(this.smartShoppingDataSet.ReportTable);
            // TODO:  這行程式碼會將資料載入 'smartShoppingDataSet1.DataTable1' 資料表。您可以視需要進行移動或移除。
            this.dataTable1TableAdapter.Fill(this.smartShoppingDataSet1.DataTable1);
            // TODO:  這行程式碼會將資料載入 'smartShoppingDataSet.View_ProductxMember' 資料表。您可以視需要進行移動或移除。


            this.reportViewer1.RefreshReport();

            this.reportViewer2.RefreshReport();
        }
예제 #21
0
        private Task <int> SendMessageAsync(CancellationToken ct, IProgress <ProgressInfo> progress)//發送簡訊非同步方法
        {
            var task = Task.Factory.StartNew(() => {
                KOT_SMSAPI mySMS = new KOT_SMSAPI(); //建之一個 KOT_SMSAPI 類別,並命名為 mySMS
                mySMS.username   = txtUsername.Text; //使用者帳號代入 [*必要項目]
                mySMS.password   = txtPassword.Text; //使用者密碼代入 [*必要項目]
                var info         = new ProgressInfo();

                using (SmartShoppingEntities SSE = new SmartShoppingEntities())
                {
                    var getlist = from inE in SSE.InsideEmailList
                                  where inE.Sent == false
                                  group inE by inE.Member_ID into g
                                  select g;

                    foreach (var group in getlist)
                    {
                        string name   = "";
                        string mobile = "";

                        //count = group.Count();//總共要發幾封

                        List <string> Products = new List <string>();
                        List <int> Quantitys   = new List <int>();
                        foreach (var send in group)
                        {
                            name   = send.MemberName;
                            mobile = send.Mobile;
                            Products.Add(send.ProductName);
                            Quantitys.Add((int)send.Quantity);
                        }

                        if (mobile == null || name == null)
                        {
                            continue;
                        }

                        //send

                        mySMS.dstaddr     = mobile; //把電話代入 (目前限單一電話) [*必要項目]
                        StringBuilder str = new StringBuilder();
                        str.Append(this.textBoxDear.Text);
                        str.Append(name);
                        str.Append(":");
                        str.Append(this.textBoxWeWill.Text);
                        str.Append(deliverydate.ToShortDateString());
                        str.Append(this.textBoxSend.Text + ":");

                        for (int j = 0; j < Products.Count; j++)
                        {
                            str.Append((j + 1) + ". " + Products[j] + "(" + Quantitys[j] + ") ");
                        }


                        str.Append("詳細資訊:http://google.com");

                        str.Append(this.textBoxNotes.Text);
                        mySMS.smbody = str.ToString(); //把簡訊內容代入 [*必要項目]



                        // 設定編碼
                        mySMS.SMSEncode = EncodingbyApp.Big5; //此若不設定,系統會自動代入預設 Big5 編碼格式


                        //========================================
                        // 呼叫傳送簡訊方法 **上述值分別設定完成後,即可呼叫 SendSMSNow 來傳送簡訊
                        //GetSMSResult = mySMS.SendSMSNow();  //呼叫傳送簡訊方法[即 SendSMSNow()],並把其結果寫入 GetSMSResult 變數中

                        if (progress != null)
                        {
                            info.Data = iSend;
                            progress.Report(info);
                        }
                        SpinWait.SpinUntil(() => { ct.ThrowIfCancellationRequested(); return(false); }, 10);

                        iSend++;
                    }
                }//=====using entity end=====//
                return(iSend);
            });



            return(task);
        }
예제 #22
0
        int count; //這次要寄信總數
        protected void SendMail()
        {
            //clear data in the list
            this.insideEmailListTableAdapter1.DeleteQuery();

            int setDateBefore = 7;

            using (SmartShoppingEntities SSE = new SmartShoppingEntities())
            {
                DateTime deliverydate = DateTime.Today.AddDays(setDateBefore);

                var q = from o in SSE.Orders
                        where o.ArrivalDate == deliverydate
                        select o; //所有今天該提醒的單
                count = q.Count();
                foreach (var item in q)
                {
                    int memberid = (int)item.Member_ID;


                    string getEmail = (from m in SSE.Members
                                       where m.Member_ID == item.Member_ID
                                       select m.Email).FirstOrDefault(); //每一張單抓到該提醒的會員的email

                    string memberName = (from m in SSE.Members
                                         where m.Member_ID == item.Member_ID
                                         select m.MemberName).FirstOrDefault();

                    var getProductName = from o in SSE.OrderDetails
                                         where o.Order_ID == item.Order_ID
                                         select o; //抓到所有商品名稱 數量
                    foreach (var od in getProductName)
                    {
                        string productName = od.Product.ProductName; //每次抓到一個商品
                        int    quantity    = (int)od.Quantity;       //抓到一個數量
                        //寫到資料庫
                        this.insideEmailListTableAdapter1.InsertQuery(memberid, memberName, getEmail, productName, deliverydate, quantity, false);
                    }
                }

                //每次讀15封 mark 已發
                var getlist = from inE in SSE.InsideEmailLists
                              where inE.Sent == false
                              group inE by inE.Member_ID into g
                              select g;

                foreach (var group in getlist)
                {
                    string name  = "";
                    string email = "";

                    //count = group.Count();//總共要發幾封

                    List <string> Products  = new List <string>();
                    List <int>    Quantitys = new List <int>();
                    foreach (var send in group)
                    {
                        name  = send.MemberName;
                        email = send.Email;
                        Products.Add(send.ProductName);
                        Quantitys.Add((int)send.Quantity);
                    }

                    if (email == null || name == null)
                    {
                        continue;
                    }

                    SmtpClient mail = new SmtpClient();
                    mail.Host                  = "smtp.gmail.com";
                    mail.EnableSsl             = true;
                    mail.UseDefaultCredentials = false;
                    NetworkCredential loginInfo = new NetworkCredential("yinghua0111", "emily75111");
                    mail.Credentials = loginInfo;

                    MailMessage mms = new MailMessage();
                    mms.From = new MailAddress("*****@*****.**", "SmartShopping Crew");
                    mms.To.Add(new MailAddress(email, name));
                    mms.Subject    = "SmartShopping發貨通知";
                    mms.IsBodyHtml = true;

                    StringBuilder str = new StringBuilder();
                    str.Append("親愛的");
                    ////從資料庫讀名字 email  商品
                    str.Append(name);
                    str.Append(":<br><br>");
                    str.Append("我們將於");
                    str.Append(deliverydate.ToShortDateString() + "<br>");
                    str.Append("寄送以下貨物給您" + ":<br><br>");
                    str.Append("<ul>");
                    for (int j = 0; j < Products.Count; j++)
                    {
                        str.Append("<li>" + Products[j] + "   數量: " + Quantitys[j] + "</li>");
                    }

                    str.Append("</ul>");
                    str.Append("<a href='http://google.com'>詳細資料</a>");
                    str.Append("<br><br>");
                    //str.Append(this.textBoxNotes.Text);

                    //string strFilePath = @"C:\Logo.gif";

                    //System.Net.Mail.Attachment attachment1 =
                    //   new System.Net.Mail.Attachment(workingDirectory);
                    //attachment1.Name = System.IO.Path.GetFileName(workingDirectory);
                    ////attachment1.NameEncoding = Encoding.GetEncoding(myMailEncoding);
                    ////attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

                    //// 設定該附件為一個內嵌附件(Inline Attachment)
                    //attachment1.ContentDisposition.Inline = true;
                    //attachment1.ContentDisposition.DispositionType =
                    //   System.Net.Mime.DispositionTypeNames.Inline;

                    //mms.Attachments.Add(attachment1);



                    mms.Body = str.ToString();



                    try
                    {
                        mail.Send(mms);
                    }
                    catch (SmtpFailedRecipientsException ex)
                    {
                        //針對發送失敗的使用者紀錄
                        for (int i = 0; i <= ex.InnerExceptions.Length; i++)
                        {
                            SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
                            if (status == SmtpStatusCode.MailboxBusy || status == SmtpStatusCode.MailboxUnavailable)
                            {
                                Console.WriteLine("信箱忙碌中");
                            }
                            else
                            {
                                Console.WriteLine("無法傳送至該信箱因{0} ", ex.InnerExceptions[i].FailedRecipient);
                            }
                        }
                        //IsCircle = true;
                        //IsSuccess = false;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception caught in RetryIfBusy(): {0}", ex.ToString());
                        //IsCircle = true;
                        //IsSuccess = false;
                    }
                    finally
                    {
                        //每發送失敗
                        //if (IsCircle)
                        //    intCount += 1;
                        //if (intCount >= intBadMailCount)
                        //    IsCircle = false;
                    }
                }
            }
        }
예제 #23
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //MessageBox.Show(e.Argument.ToString());//取得傳入的參數100

            e.Result = iSend;

            //每次讀15封 mark 已發
            using (SmartShoppingEntities SSE = new SmartShoppingEntities())
            {
                var getlist = from inE in SSE.InsideEmailList
                              where inE.Sent == false
                              group inE by inE.Member_ID into g
                              select g;

                foreach (var group in getlist)
                {
                    if (backgroundWorker1.CancellationPending)//取消按下去的話
                    {
                        e.Cancel = true;
                        break;
                    }

                    string name  = "";
                    string email = "";


                    //count = group.Count();//總共要發幾封

                    List <string> Products  = new List <string>();
                    List <int>    Quantitys = new List <int>();
                    foreach (var send in group)
                    {
                        name  = send.MemberName;
                        email = send.Email;

                        Products.Add(send.ProductName);
                        Quantitys.Add((int)send.Quantity);
                    }

                    if (email == null || name == null)
                    {
                        continue;
                    }

                    //開始寄信
                    SmtpClient mail = new SmtpClient();
                    mail.Host                  = "smtp.gmail.com";
                    mail.EnableSsl             = true;
                    mail.UseDefaultCredentials = false;
                    NetworkCredential loginInfo = new NetworkCredential("yinghua0111", "emily75111");
                    mail.Credentials = loginInfo;

                    MailMessage mms = new MailMessage();
                    mms.From = new MailAddress("*****@*****.**", "SmartShopping Crew");
                    mms.To.Add(new MailAddress(email, name));
                    mms.Subject    = this.textBoxSubject.Text;
                    mms.IsBodyHtml = true;
                    StringBuilder str = new StringBuilder();
                    str.Append(this.textBoxDear.Text);
                    str.Append(name);
                    str.Append(":<br><br>");
                    str.Append(this.textBoxWeWill.Text);
                    str.Append(deliverydate.ToShortDateString() + "<br>");
                    str.Append(this.textBoxSend.Text + ":<br><br>");
                    str.Append("<ul>");
                    for (int j = 0; j < Products.Count; j++)
                    {
                        str.Append("<li>" + Products[j] + "   數量: " + Quantitys[j] + "</li>");
                    }

                    str.Append("</ul>");
                    str.Append("<a href='http://google.com'>詳細資料</a>");
                    str.Append("<br><br>");
                    str.Append(this.textBoxNotes.Text);
                    //把字串存到資料庫給服務用
                    str.Append("<img scr='http://gifcountdown.com/asia-makassar/1424955600/141414/0f0f0f/aaaaaa/fdfdfd/faedad/true/counter.gif'></img>");


                    if (withAd)//有勾隨信附上廣告才會加入HTML字串
                    {
                        str.Append(AdHTML);
                        if (filePath != string.Empty)
                        {
                            System.Net.Mail.Attachment attachment1 = new System.Net.Mail.Attachment(filePath);
                            attachment1.Name = System.IO.Path.GetFileName(filePath);
                            //attachment1.NameEncoding = Encoding.GetEncoding(myMailEncoding);
                            //attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

                            // 設定該附件為一個內嵌附件(Inline Attachment)
                            attachment1.ContentDisposition.Inline          = true;
                            attachment1.ContentDisposition.DispositionType =
                                System.Net.Mime.DispositionTypeNames.Inline;

                            mms.Attachments.Add(attachment1);
                        }
                    }

                    //身分問題  圖先寫進資料庫
                    str.Append("<hr/>");
                    str.Append("<p style='text-align:center'><a href='https://localhost:44300/MemberCenter/CancelEmailAd?Confirmed=false'>我不要再收到通知信</a></p>");
                    mms.Body = str.ToString();


                    mail.Send(mms);
                    //設定進度表
                    p = (int)Math.Round(iSend * 1.0 / count * 100);

                    backgroundWorker1.ReportProgress(p);
                    iSend++;
                }
                //撈下15封到沒有
            }
            e.Result = iSend;
        }