private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure? do you want to delete this product?", "Deleting product", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         ListView.SelectedListViewItemCollection SLV = this.ProductsList.SelectedItems;
         if (SLV.Count > 0)
         {
             try
             {
                 var PInfo = ProductsInfos.AllProducts[SLV[0].Text];
                 for (int p = 0; p <= ProductsLog.AllLogs.Count; p++)// foreach (ProductsLog PL2 in ProductsLog.AllLogs)
                 {
                     ProductsLog PL2 = ProductsLog.AllLogs[p];
                     if (PL2.ID == PInfo.PID)
                     {
                         ProductLogController(PL2, true);
                     }
                 }
                 MySqlConnection conn = new MySqlConnection(Program.connStr);
                 string          s0   = "use aleman_cafe_server; DELETE FROM products WHERE id='" + PInfo.PID + "';";
                 conn.Open();
                 MySqlCommand cmd = new MySqlCommand(s0, conn);
                 cmd.ExecuteNonQuery();
                 ProductController(PInfo, false, true);
                 conn.Close();
                 conn = new MySqlConnection(Program.connStr);
                 conn.Open();
                 s0  = "use aleman_cafe_server; DELETE FROM productslog WHERE id='" + PInfo.PID + "';";
                 cmd = new MySqlCommand(s0, conn);
                 cmd.ExecuteNonQuery();
                 conn.Close();
             }catch (Exception ee) { MessageBox.Show("Error : " + ee.ToString()); }
         }
     }
 }
Пример #2
0
 public static void Add(ProductsLogEnum type, int productId, string parameter, int userId)
 {
     ProductsLog record = new ProductsLog();
     record.LogParameter = parameter;
     record.LogType = (int)type;
     record.ProductId = productId;
     record.LogDate = DateTime.Now;
     record.UserId = userId;
     CanonDataContext db = Cdb.Instance;
     db.ProductsLogs.InsertOnSubmit(record);
     db.SubmitChanges();
 }
Пример #3
0
 public static void Add(int channelId, int productId, MappingLogEnum type)
 {
     ProductsLog pl = new ProductsLog();
     pl.ChannelId = channelId;
     pl.ProductId = productId;
     pl.LogType = (int)type;
     pl.LogDate = DateTime.Now;
     if (WebVariables.LoggedUserId != 0)
         pl.UserId = WebVariables.LoggedUserId;
     CanonDataContext db = Cdb.Instance;
     db.ProductsLogs.InsertOnSubmit(pl);
     db.SubmitChanges();
 }
Пример #4
0
        public static void Add(ProductsLogEnum type, int productId, string parameter, int userId)
        {
            ProductsLog record = new ProductsLog();

            record.LogParameter = parameter;
            record.LogType      = (int)type;
            record.ProductId    = productId;
            record.LogDate      = DateTime.Now;
            record.UserId       = userId;
            CanonDataContext db = Cdb.Instance;

            db.ProductsLogs.InsertOnSubmit(record);
            db.SubmitChanges();
        }
Пример #5
0
        public IActionResult Delete(int id)
        {
            ProductsLog productsLog = _context.ProductsLogs.Find(id);

            if (productsLog == null)
            {
                var error = returnObject("Log not found", 404, 0);
                return(NotFound(error));
            }
            _context.ProductsLogs.Remove(productsLog);
            _context.SaveChanges();
            var message = returnObject("Log deleted correctly", 200, 1);

            return(Ok(message));
        }
Пример #6
0
        public static void Add(int channelId, int productId, MappingLogEnum type)
        {
            ProductsLog pl = new ProductsLog();

            pl.ChannelId = channelId;
            pl.ProductId = productId;
            pl.LogType   = (int)type;
            pl.LogDate   = DateTime.Now;
            if (WebVariables.LoggedUserId != 0)
            {
                pl.UserId = WebVariables.LoggedUserId;
            }
            CanonDataContext db = Cdb.Instance;

            db.ProductsLogs.InsertOnSubmit(pl);
            db.SubmitChanges();
        }
Пример #7
0
 public IActionResult Post([FromBody] ProductsLog productsLog)
 {
     try
     {
         productsLog.BuyingDate = DateTime.Now;
         _context.Add(productsLog);
         _context.SaveChanges();
         var message = returnObject("Log added correctly", 200, 1);
         return(Ok(message));
     }
     catch (Exception ex)
     {
         string e     = ex.Message;
         var    error = returnObject(e, 400, 0);
         return(BadRequest(error));
     }
 }
Пример #8
0
 public IActionResult Put([FromBody] ProductsLog productsLog)
 {
     try
     {
         ProductsLog _productsLog = _context.ProductsLogs.FirstOrDefault(x => x.ProductsLogId == productsLog.ProductsLogId);
         _productsLog.UserId    = productsLog.UserId;
         _productsLog.ProductId = productsLog.ProductId;
         _context.SaveChanges();
         var message = returnObject("Log modified correctly", 200, 1);
         return(Ok(message));
     }
     catch (Exception ex)
     {
         string e     = ex.Message;
         var    error = returnObject(e, 400, 0);
         return(BadRequest(error));
     }
 }
        public void ProductLogController(ProductsLog PL, bool Delete = false)
        {
            if (Delete)
            {
                for (int sSs = 0; sSs < SalesLogView.Items.Count; sSs++)//foreach(ListView.ListViewItemCollection ss in SalesLogView.Items)
                {
                    ListViewItem ss = SalesLogView.Items[sSs];
                    if (ss.SubItems[7].Text == PL.At.ToString())
                    {
                        SalesLogView.Items.Remove(ss);
                    }
                }

                /*
                 * var elv = SalesLogView.Items.Find(PL.ID.ToString(), false);
                 * if (elv.Length > 0)
                 *  this.SalesLogView.Items.Remove(elv[0]);
                 */
                ProductsLog.AllLogs.Remove(PL);
                TotalLogs.Text = ProductsLog.AllLogs.Count.ToString();
                return;
            }
            var PI = ProductsInfos.AllProducts[PL.ID.ToString()];

            string[] Items = new string[8];
            Items[0] = PL.ID.ToString();
            Items[1] = PI.PName;
            Items[2] = PI.PType;
            Items[3] = PL.Price.ToString();
            Items[4] = PI.Price.ToString();
            Items[5] = PL.Quantity.ToString();
            Items[6] = PL.LogType.ToString();
            Items[7] = PL.At.ToString();
            //name, type, price, purchasingprice, count, noofsales, needed, details, picurl) "+
            ListViewItem LV = new ListViewItem(Items);

            LV.Name        = LV.Text = PI.PID.ToString();
            LV.ToolTipText = "Name : " + PI.PName + Environment.NewLine +
                             "Type : " + PI.PType + Environment.NewLine +
                             "Price : " + PI.Price + Environment.NewLine +
                             "Purchasing Price : " + PI.PPrice + Environment.NewLine +
                             "Count : " + PI.Count + Environment.NewLine +
                             "Number of sales : " + PI.NoOfSales + Environment.NewLine +
                             "Needed count : " + PI.NeededCount + Environment.NewLine +
                             "Details : " + PI.Details + Environment.NewLine +
                             "Action : " + PL.LogType.ToString() + Environment.NewLine +
                             "Quantity : " + PL.Quantity + Environment.NewLine +
                             "DateTime : " + PL.At.ToString();

            if (string.IsNullOrEmpty(PI.ImageURL))
            {
                LV.ImageKey = "LoginMonitor";
            }
            else
            {
                try
                {
                    if (!SalesLogView.LargeImageList.Images.ContainsKey(PI.ImageURL))
                    {
                        if (this.SalesLogView.InvokeRequired)
                        {
                            this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                              () => this.SalesLogView.LargeImageList.Images.Add(PI.ImageURL, Image.FromFile(ProductsInfos.ImagesURL + PI.ImageURL))));
                        }
                        else
                        {
                            this.SalesLogView.LargeImageList.Images.Add(PI.ImageURL, Image.FromFile(ProductsInfos.ImagesURL + PI.ImageURL));
                        }
                    }
                    if (!SalesLogView.SmallImageList.Images.ContainsKey(PI.ImageURL))
                    {
                        if (this.SalesLogView.InvokeRequired)
                        {
                            this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                              () => this.SalesLogView.SmallImageList.Images.Add(PI.ImageURL, Image.FromFile(ProductsInfos.ImagesURL + PI.ImageURL))));
                        }
                        else
                        {
                            this.SalesLogView.SmallImageList.Images.Add(PI.ImageURL, Image.FromFile(ProductsInfos.ImagesURL + PI.ImageURL));
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ProductsInfos.ImagesURL + PI.ImageURL + Environment.NewLine + ex.ToString());
                }
                LV.ImageKey = PI.ImageURL;
            }


            if (!ProductsLog.AllLogs.Contains(PL))
            {
                ProductsLog.AllLogs.Add(PL);
                TotalLogs.Text = ProductsLog.AllLogs.Count.ToString();
            }

            if (this.SalesLogView.InvokeRequired)
            {
                this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                  () => this.SalesLogView.Items.Add(LV)));
            }
            else
            {
                this.SalesLogView.Items.Add(LV);
            }
            Application.DoEvents();
        }
        //  protected override void OnLoad(EventArgs e)
        public bool LoadProducts()
        {
            #region Images

            if (this.ProductsList.InvokeRequired)
            {
                this.ProductsList.BeginInvoke(new MethodInvoker(
                                                  () => this.ProductsList.LargeImageList = new ImageList()));
            }
            else
            {
                this.ProductsList.LargeImageList = new ImageList();
            }

            if (this.ProductsList.InvokeRequired)
            {
                this.ProductsList.BeginInvoke(new MethodInvoker(
                                                  () => this.ProductsList.LargeImageList.ImageSize = new Size(100, 100)));
            }
            else
            {
                this.ProductsList.LargeImageList.ImageSize = new Size(100, 100);
            }


            if (this.ProductsList.InvokeRequired)
            {
                this.ProductsList.BeginInvoke(new MethodInvoker(
                                                  () => this.ProductsList.SmallImageList = new ImageList()));
            }
            else
            {
                this.ProductsList.SmallImageList = new ImageList();
            }

            if (this.ProductsList.InvokeRequired)
            {
                this.ProductsList.BeginInvoke(new MethodInvoker(
                                                  () => this.ProductsList.SmallImageList.ImageSize = new Size(22, 31)));
            }
            else
            {
                this.ProductsList.SmallImageList.ImageSize = new Size(22, 31);
            }


            if (this.ProductsList.InvokeRequired)
            {
                this.ProductsList.BeginInvoke(new MethodInvoker(
                                                  () => this.ProductsList.LargeImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor)));
            }
            else
            {
                this.ProductsList.LargeImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor);
            }

            if (this.ProductsList.InvokeRequired)
            {
                this.ProductsList.BeginInvoke(new MethodInvoker(
                                                  () => this.ProductsList.SmallImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor)));
            }
            else
            {
                this.ProductsList.SmallImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor);
            }

            //*********
            if (this.SalesLogView.InvokeRequired)
            {
                this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                  () => this.SalesLogView.LargeImageList = new ImageList()));
            }
            else
            {
                this.SalesLogView.LargeImageList = new ImageList();
            }

            if (this.SalesLogView.InvokeRequired)
            {
                this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                  () => this.SalesLogView.LargeImageList.ImageSize = new Size(100, 100)));
            }
            else
            {
                this.SalesLogView.LargeImageList.ImageSize = new Size(100, 100);
            }


            if (this.SalesLogView.InvokeRequired)
            {
                this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                  () => this.SalesLogView.SmallImageList = new ImageList()));
            }
            else
            {
                this.SalesLogView.SmallImageList = new ImageList();
            }

            if (this.SalesLogView.InvokeRequired)
            {
                this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                  () => this.SalesLogView.SmallImageList.ImageSize = new Size(22, 31)));
            }
            else
            {
                this.SalesLogView.SmallImageList.ImageSize = new Size(22, 31);
            }


            if (this.SalesLogView.InvokeRequired)
            {
                this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                  () => this.SalesLogView.LargeImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor)));
            }
            else
            {
                this.SalesLogView.LargeImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor);
            }

            if (this.SalesLogView.InvokeRequired)
            {
                this.SalesLogView.BeginInvoke(new MethodInvoker(
                                                  () => this.SalesLogView.SmallImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor)));
            }
            else
            {
                this.SalesLogView.SmallImageList.Images.Add("LoginMonitor", Properties.Resources.LoginMonitor);
            }
            #endregion

            if (!Directory.Exists(ProductsInfos.ImagesURL))
            {
                Directory.CreateDirectory(ProductsInfos.ImagesURL);
            }
            MySqlConnection conn = new MySqlConnection(Program.connStr);

            conn = new MySqlConnection(Program.connStr);
            conn.Open();
            string       s0  = "use `aleman_cafe_server`; SELECT * FROM `products`";
            MySqlCommand cmd = new MySqlCommand(s0, conn);
            try
            {
                var rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    ProductsInfos PI = new ProductsInfos(rdr);
                    ProductController(PI);
                    if (!ProductsInfos.PTypes.Contains(rdr.GetString(2)))
                    {
                        ProductsInfos.PTypes.Add(rdr.GetString(2));
                    }
                    int MID = rdr.GetInt32(0);
                    if (MID >= ProductsInfos.NextID)
                    {
                        ProductsInfos.NextID = (MID + 1);
                    }
                }
                rdr.Close();
                conn.Close();
            }
            catch (Exception ee)
            {
                conn.Close();
                //  MessageBox.Show("There are an error and database cannot be loaded." + Environment.NewLine + ee.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (MessageBox.Show("There are an error and database cannot be loaded, do you want to create new database?" + Environment.NewLine + ee.ToString(), "Database Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    MyDatabase.CreateDB();
                }
                this.ReloadList();
            }

            s0 = "use `aleman_cafe_server`; SELECT * FROM `productslog`";
            conn.Open();
            var TodayLogs = new List <ProductsLog>();
            cmd = new MySqlCommand(s0, conn);
            try
            {
                var rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    ProductsLog PL = new ProductsLog(rdr);
                    if (PL.At.Date == DateTime.Now.Date && !TodayLogs.Contains(PL))
                    {
                        TodayLogs.Add(PL);
                    }
                    ProductLogController(PL);
                }
                rdr.Close();
                conn.Close();
            }
            catch (Exception ee)
            {
                conn.Close();
                //  MessageBox.Show("There are an error and database cannot be loaded." + Environment.NewLine + ee.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (MessageBox.Show("There are an error and database 'productslog' cannot be loaded, do you want to create new database?" + Environment.NewLine + ee.ToString(), "Database Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    MyDatabase.CreateDB();
                }
                this.ReloadList();
            }
            var WU = new List <int>();
            foreach (var N in TodayLogs)
            {
                var PI = ProductsInfos.AllProducts[N.ID.ToString()];
                if (N.LogType == ProductsLog.LogTypes.Sold)
                {
                    PI.SoldToday += N.Quantity;
                }
                else
                {
                    PI.SoldToday -= N.Quantity;
                }
                if (!WU.Contains(PI.PID))
                {
                    WU.Add(PI.PID);
                }
            }

            foreach (int i in WU)
            {
                var PI = ProductsInfos.AllProducts[i.ToString()];
                ProductController(PI, true);
            }

            /*
             * this.thumbnailsToolStripMenuItem.Click += new System.EventHandler(this.thumbnailsToolStripMenuItem_Click);
             * this.tilesToolStripMenuItem.Click += new System.EventHandler(this.tilesToolStripMenuItem_Click);
             * this.iconsToolStripMenuItem.Click += new System.EventHandler(this.iconsToolStripMenuItem_Click);
             * this.listToolStripMenuItem.Click += new System.EventHandler(this.listToolStripMenuItem_Click);
             * this.detailsToolStripMenuItem.Click += new System.EventHandler(this.detailsToolStripMenuItem_Click);
             * this.AddProductButton.Click += new System.EventHandler(this.AddProductButton_Click);
             */
            ProductsList.MouseClick           += new MouseEventHandler(ProductsList_MouseClick);
            ProductsList.MouseDoubleClick     += new MouseEventHandler(ProductsList_MouseClick);
            ProductsList.KeyDown              += new KeyEventHandler(ProductsList_KeyPress);
            ProductsList.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(ProductsList_ItemSelectionChanged);
            ProductsList.ColumnClick          += ProductsList_ColumnClick;

            SearchText.TextChanged += SearchText_TextChanged;

            FromdatePicker.ValueChanged += FromdatePicker_ValueChanged;
            TodatePicker.ValueChanged   += FromdatePicker_ValueChanged;
            return(true);
        }