Ejemplo n.º 1
0
        private void button10_Click(object sender, EventArgs e)
        {
            button9.Enabled  = true;
            button11.Enabled = false;

            DataGridViewRow row            = dataGridView4.Rows[dataGridView4.CurrentCell.RowIndex];
            string          SelectedPIDsrt = row.Cells[0].Value.ToString();
            int             SelectedPID    = Int32.Parse(SelectedPIDsrt);

            PublicSelectedPID = SelectedPID;

            Com.Product SelectedProduct = AllDoreProducts.Where(W => W.PID == SelectedPID).SingleOrDefault();
            textBox12.Text    = SelectedProduct.Name;
            textBox16.Text    = SelectedProduct.Price.ToString();
            textBox15.Text    = SelectedProduct.Discount.ToString();
            checkBox1.Checked = SelectedProduct.Available;
            richTextBox2.Text = SelectedProduct.Description;

            var serializer = new JavaScriptSerializer();

            Com.SpecDore specDore = serializer.Deserialize <Com.SpecDore>(SelectedProduct.specifications);

            foreach (var itemagenda in specDore.agenda)
            {
                listBoxSarFasl.Items.Add(itemagenda);
            }

            textBox17.Text                  = specDore.CourseDuration.ToString();
            dateTimePicker2.Value           = specDore.EndDate;
            dateTimePicker1.Value           = specDore.StartDate;
            comboBoxDoreSatate.SelectedItem = specDore.State;

            foreach (var itemTeacher in specDore.Teachers)
            {
                listBoxAsatid.Items.Add(itemTeacher.Name);
            }

            foreach (var itemQF in specDore.FAQ)
            {
                dataGridView3.Rows.Add(itemQF.Question, itemQF.Answer);
            }
            foreach (var itemEss in specDore.Sessions)
            {
                dataGridView2.Rows.Add(itemEss.Title, itemEss.Date, itemEss.Time);
            }


            System.Net.WebRequest  request  = System.Net.WebRequest.Create("https://www.hasma.ir/FitnessResource/Product/" + SelectedProduct.PID.ToString() + "/0.jpg");
            System.Net.WebResponse response = request.GetResponse();
            Stream responseStream           = response.GetResponseStream();

            pictureBox2.Image = new Bitmap(responseStream);
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            buttonAddBook.Enabled = false;
            button3.Enabled       = true;
            button2.Enabled       = true;

            DataGridViewRow row            = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex];
            string          SelectedPIDsrt = row.Cells[0].Value.ToString();
            int             SelectedPID    = Int32.Parse(SelectedPIDsrt);

            PublicSelectedPID = SelectedPID;

            Com.Product SelectedProduct = AllBookProducts.Where(W => W.PID == SelectedPID).SingleOrDefault();

            richTextBox1.Text = SelectedProduct.Description;
            textBoxName.Text  = SelectedProduct.Name;
            textBox13.Text    = SelectedProduct.Price.ToString();
            textBox14.Text    = SelectedProduct.Discount.ToString();
            int ImgCount = Int32.Parse(SelectedProduct.Img);

            checkBox2.Checked = SelectedProduct.Available;
            var     serializer = new JavaScriptSerializer();
            SpecObj spec       = serializer.Deserialize <SpecObj>(SelectedProduct.specifications);

            textBox1.Text  = spec.Nevisande;
            textBox3.Text  = spec.GerdAavari;
            textBox2.Text  = spec.Nasher;
            textBox5.Text  = spec.Mozoo;
            textBox10.Text = spec.Vazn;
            textBox4.Text  = spec.NobateChap;
            textBox6.Text  = spec.SaleChap;
            textBox7.Text  = spec.TedadeSafhe;
            textBox8.Text  = spec.Ghat;
            textBox9.Text  = spec.Shabok;
            textBox11.Text = spec.MonasebBaraye;
            for (int i = 0; i < ImgCount; i++)
            {
                try
                {
                    System.Net.WebRequest  request  = System.Net.WebRequest.Create("https://www.hasma.ir/FitnessResource/Product/" + SelectedProduct.PID.ToString() + "/" + ImgCount + ".jpg");
                    System.Net.WebResponse response = request.GetResponse();
                    Stream responseStream           = response.GetResponseStream();
                    publicBitmapBookSelected = new Bitmap(responseStream);
                    imageList1.Images.Add(publicBitmapBookSelected);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <string> PostToServerUpdateProduct(Com.Product mPproduct)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    using (var form = new MultipartFormDataContent())
                    {
                        StringContent contentBody = new StringContent(JsonConvert.SerializeObject(mPproduct));
                        form.Add(contentBody, "Object");

                        foreach (var ImgItem in imageList1.Images)
                        {
                            ImageConverter imgConverter = new ImageConverter();
                            var            imgBytes     = (System.Byte[])imgConverter.ConvertTo(ImgItem, Type.GetType("System.Byte[]"));
                            var            fileContent  = new ByteArrayContent(imgBytes);
                            fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
                            form.Add(fileContent, "File", ".jpg");
                        }

                        //ImageConverter imgConverter = new ImageConverter();
                        //var imgBytes = (System.Byte[])imgConverter.ConvertTo(pictureBox1.Image, Type.GetType("System.Byte[]"));
                        //var fileContent = new ByteArrayContent(imgBytes);
                        //fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
                        //form.Add(fileContent, "File", ".jpg");

                        HttpResponseMessage response = await httpClient.PostAsync(BaseAddress + "fitness/Shop/PostUpdateProduct", form);

                        if (response.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            return("Ok");
                        }
                        else
                        {
                            return("Error");
                        }
                    }
                }
            }
            catch (Exception eeee)
            {
                Console.WriteLine(eeee.Message);
                MessageBox.Show("مشکل در ارسال پست");
                MessageBox.Show(eeee.Message);
                return("Error");
            }
        }
Ejemplo n.º 4
0
        public static int AddProduct(Com.Product mProduct)
        {
            try
            {
                using (var ent = DB.Entity)
                {
                    ent.Products.Add(mProduct);
                    ent.SaveChanges();

                    return(mProduct.PID);
                }
            }
            catch (Exception e)
            {
                Log.DoLog(Com.Common.Action.AddProduct, "", -100, e.Message);
                return(-100);
            }
        }
Ejemplo n.º 5
0
 public static bool UpdateProductImgNumber(Com.Product mProduct)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Products.Attach(mProduct);
             var Entry = ent.Entry(mProduct);
             Entry.Property(ex => ex.Img).IsModified = true;
             ent.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(Com.Common.Action.UpdateProductImgNumber, mProduct.PID.ToString(), -100, e.Message);
         return(false);
     }
 }
Ejemplo n.º 6
0
 public static bool UpdateProduct(Com.Product mProduct)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Products.Attach(mProduct);
             var Entry = ent.Entry(mProduct);
             Entry.Property(ex => ex.Description).IsModified    = true;
             Entry.Property(ex => ex.Discount).IsModified       = true;
             Entry.Property(ex => ex.Price).IsModified          = true;
             Entry.Property(ex => ex.specifications).IsModified = true;
             Entry.Property(ex => ex.Name).IsModified           = true;
             ent.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(Com.Common.Action.UpdateProduct, mProduct.PID.ToString(), -100, e.Message);
         return(false);
     }
 }
Ejemplo n.º 7
0
        private async void button11_Click(object sender, EventArgs e)
        {
            try
            {
                List <Com.FQ> fqs = new List <Com.FQ>();

                foreach (DataGridViewRow itemFQ in dataGridView3.Rows)
                {
                    if (itemFQ.IsNewRow)
                    {
                        continue;
                    }
                    try
                    {
                        Com.FQ fQ = new Com.FQ()
                        {
                            Answer   = itemFQ.Cells[1].Value.ToString(),
                            Question = itemFQ.Cells[0].Value.ToString(),
                        };
                        fqs.Add(fQ);
                    }
                    catch
                    { }
                }

                List <Com.Sess> sesses = new List <Com.Sess>();
                foreach (DataGridViewRow itemFQ in dataGridView2.Rows)
                {
                    if (itemFQ.IsNewRow)
                    {
                        continue;
                    }
                    try
                    {
                        Com.Sess sess = new Com.Sess()
                        {
                            Date  = itemFQ.Cells[1].Value.ToString(),
                            Time  = itemFQ.Cells[2].Value.ToString(),
                            Title = itemFQ.Cells[0].Value.ToString(),
                        };
                        sesses.Add(sess);
                    }
                    catch
                    { }
                }

                List <Com.Teacher> teacherssss = new List <Com.Teacher>();

                foreach (var itemTT in listBoxAsatid.Items)
                {
                    var te = AllTeachers.Where(W => W.Name == (string)itemTT).SingleOrDefault();
                    teacherssss.Add(te);
                }


                Com.SpecDore specDore = new Com.SpecDore()
                {
                    agenda         = listBoxSarFasl.Items.Cast <String>().ToList(),
                    CourseDuration = Int32.Parse(textBox17.Text),
                    EndDate        = dateTimePicker2.Value,
                    StartDate      = dateTimePicker1.Value,
                    FAQ            = fqs,
                    Sessions       = sesses,
                    State          = (string)comboBoxDoreSatate.SelectedItem,
                    Teachers       = teacherssss
                };

                Com.Product newProduct = new Com.Product()
                {
                    Available      = checkBox1.Checked,
                    CatID          = 2,
                    Description    = richTextBox2.Text,
                    Discount       = Int32.Parse(textBox15.Text),
                    Img            = "",
                    Name           = textBox12.Text,
                    Price          = Int32.Parse(textBox16.Text),
                    specifications = JsonConvert.SerializeObject(specDore)
                };

                var xx = await PostToServerDoreProduct(newProduct);

                Console.WriteLine(xx);
                if (xx == "Error")
                {
                    MessageBox.Show("آپلود نشد مشکل در سرور.");
                }
                else
                {
                    MessageBox.Show("آپلود شد.");
                    GetDataANDRefreshGridViewDore();
                }
            }
            catch (Exception eex)
            {
                MessageBox.Show("آپلود نشد مشکل در ورودی ها.");
            }
        }
Ejemplo n.º 8
0
        private async void button3_Click(object sender, EventArgs e)
        {
            SpecObj spec = new SpecObj()
            {
                GerdAavari    = textBox3.Text,
                Ghat          = textBox8.Text,
                MonasebBaraye = textBox11.Text,
                Mozoo         = textBox5.Text,
                Nasher        = textBox2.Text,
                Nevisande     = textBox1.Text,
                NobateChap    = textBox4.Text,
                SaleChap      = textBox6.Text,
                Shabok        = textBox11.Text,
                TedadeSafhe   = textBox7.Text,
                Vazn          = textBox10.Text,
            };

            Com.Product UpProduct = new Com.Product()
            {
                PID            = PublicSelectedPID,
                CatID          = 1,
                Available      = checkBox2.Checked,
                Description    = richTextBox1.Text,
                Discount       = Int32.Parse(textBox14.Text),
                Img            = "",
                Name           = textBoxName.Text,
                Price          = Int32.Parse(textBox13.Text),
                specifications = JsonConvert.SerializeObject(spec)
            };

            var xx = await PostToServerUpdateProduct(UpProduct);

            Console.WriteLine(xx);
            if (xx == "Error")
            {
                MessageBox.Show("آپدیت نشد مشکل در سرور.");
            }
            else
            {
                MessageBox.Show("آپدیت شد.");
                GetDataANDRefreshGridView();

                listView1.Items.Clear();
                imageList1.Images.Clear();
                textBox3.Text     = "";
                textBox8.Text     = "";
                textBox11.Text    = "";
                textBox5.Text     = "";
                textBox2.Text     = "";
                textBox1.Text     = "";
                textBox4.Text     = "";
                textBox6.Text     = "";
                textBox11.Text    = "";
                textBox7.Text     = "";
                textBox10.Text    = "";
                richTextBox1.Text = "";
                textBox14.Text    = "";
                textBoxName.Text  = "";
                textBox13.Text    = "";
            }
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> PostUpdateProduct()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    return(StatusCode(HttpStatusCode.UnsupportedMediaType));
                }

                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                Com.Product mProduct = new Com.Product();

                int Imgcount = 0;

                foreach (var itemContent in filesReadToProvider.Contents)
                {
                    if (itemContent.Headers.ContentDisposition.Name == "Object")
                    {
                        var jsonString = await itemContent.ReadAsStringAsync();

                        var serializer = new JavaScriptSerializer();
                        mProduct = serializer.Deserialize <Com.Product>(jsonString);

                        if (!BLL.Product.UpdateProduct(mProduct))
                        {
                            return(BadRequest());
                        }
                    }
                    else if (itemContent.Headers.ContentDisposition.Name == "File")
                    {
                        string rootFolder = @"C:\inetpub\wwwroot\FitnessResource\Product\" + mProduct.PID;

                        if (!Directory.Exists(rootFolder))
                        {
                            Directory.CreateDirectory(rootFolder);
                        }

                        string[] files = Directory.GetFiles(rootFolder);
                        foreach (var file in files)
                        {
                            File.Delete(file);
                        }

                        var fileBytes = await itemContent.ReadAsByteArrayAsync();

                        string HeaderType = itemContent.Headers.ContentDisposition.FileName;

                        string NameNewFile = System.Web.Hosting.HostingEnvironment.MapPath("~/FitnessResource/Product/" + mProduct.PID);

                        if (!Directory.Exists(NameNewFile))
                        {
                            Directory.CreateDirectory(NameNewFile);
                        }

                        NameNewFile = NameNewFile + "/" + Imgcount.ToString() + HeaderType;

                        File.WriteAllBytes(NameNewFile, fileBytes);

                        Imgcount++;


                        mProduct.Img = Imgcount.ToString();

                        BLL.Product.UpdateProductImgNumber(mProduct);
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }

                return(Ok());
            }
            catch (Exception ee)
            {
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostUpdateProduct, "", -400, ee.Message); }).Start();
                return(BadRequest());
            }
        }
Ejemplo n.º 10
0
 public int AddProduct([FromBody] Com.Product product)
 {
     return(BLL.Product.AddProduct(product));
 }