Beispiel #1
0
        //chưa làm
        //public DetailSP(List<string> _stt, List<string> _buoclam, List<string> _hinhanh)
        //{
        //    stepdo = new List<StepDo>();
        //    hinhanh = _hinhanh;
        //}

        public void Find(string id)
        {
            string    sql = $"SELECT* FROM CTSP WHERE MaSP = {id} ORDER BY STT";
            DataTable dt  = Connection.GetALL_Data(sql);

            foreach (DataRow row in dt.Rows)
            {
                StepDo stp = new StepDo();
                masp     = row["MaSP"].ToString();
                stp.step = (row["STT"].ToString());
                stp.Do   = (row["Buoclam"].ToString());
                stepdo.Add(stp);
            }
            string    sql2 = $"select* from HinhAnh where MaSP = {id}";
            DataTable dt2  = Connection.GetALL_Data(sql2);

            foreach (DataRow row2 in dt2.Rows)
            {
                this.hinhanh.Add(row2["HinhAnh"].ToString());
            }
        }
Beispiel #2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            List <TextBox> childrenOfIngredients = AllChildren(Ingredients);
            List <TextBox> childrenOfSteps       = AllChildren(Steps);
            FileInfo       info       = null;
            var            folderfile = AppDomain.CurrentDomain.BaseDirectory;
            var            newname    = "";

            // Ảnh đại diện: _fileAvatar
            // Tên món ăn: ProductName.Text
            // Mô tả: ProductIntro.Text
            // Danh mục: Categories.SelectedItem; (xem lại)

            // Thời gian nấu: Time.Text
            // Nguyên liệu được thêm vào childrenOfIngredients

            // Kiểm tra dữ liệu
            if (ConditionCheck(childrenOfIngredients, childrenOfSteps))
            {
                info = new FileInfo(_fileAvatar);

                newname = $"{Guid.NewGuid()}{info.Extension}";
                //copy vào file
                info.CopyTo($"{folderfile}Resource\\Images\\Product\\{newname}");

                //them vao chổ sp
                SanPham sp = new SanPham();
                sp.AnhDaiDien = "Resource/Images/Product/" + newname;
                if (ProductName.Text.Trim() != "")
                {
                    sp.TenSP = ProductName.Text.Trim();
                }
                if (ProductIntro.Text.Trim() != "")
                {
                    sp.MoTa = ProductIntro.Text.Trim();
                }
                sp.Video    = ProductVideo.Text;
                sp.MaDM     = (Categories.SelectedIndex + 1).ToString();
                sp.ThoiGian = Time.Text.Trim();

                foreach (var element in childrenOfIngredients)
                {
                    if (element.Text.Trim() != "")
                    {
                        sp.NguyenLieu += element.Text + "\\n";
                    }
                }
                sp.SoThanhPhan = childrenOfIngredients.Count;
                ///thêm đối tượng sp vào database
                sp.Add();

                DetailSP ctsp = new DetailSP();

                for (int i = 1; i <= childrenOfSteps.Count; i++)
                {
                    StepDo stp = new StepDo();
                    stp.step = (i.ToString());
                    stp.Do   = (childrenOfSteps[i - 1].Text);
                    ctsp.stepdo.Add(stp);
                }

                //// List ảnh các bước làm _stepImageList
                foreach (var av in _stepImageList)
                {
                    if (av.Name != null)
                    {
                        newname = $"{Guid.NewGuid()}{av.Extension}";
                        av.CopyTo($"{folderfile}Resource\\Images\\Product\\{newname}");
                        string path = $"Resource/Images/Product/{newname}";
                        ctsp.hinhanh.Add(path);
                    }
                }

                ////thêm ctsp vào database
                ctsp.Add();
                DialogResult = true;
            }
        }