private void btnAddItem_Click(object sender, RoutedEventArgs e)
        {
            var  fb = this.DataContext as FormedBasket;
            Item i;

            if (lbItemsFiltered.Visibility == Visibility.Visible)
            {
                if (lbItemsFiltered.SelectedIndex == -1)
                {
                    return;
                }
                var iFiltered = lbItemsFiltered.SelectedItem as Item;
                i = (lbMainItems.ItemsSource as List <Item>).Where(x => x.Id == iFiltered.Id).FirstOrDefault();
                txtSearch.Text = string.Empty;
            }
            else
            {
                if (lbMainItems.SelectedIndex == -1)
                {
                    return;
                }
                i = lbMainItems.SelectedItem as Item;
            }
            FormedBasket_Item s = new FormedBasket_Item();

            s.RelatedItem = i;
            s.Quantity    = 1;

            (dgSelectedItems.ItemsSource as List <FormedBasket_Item>).Add(s);
            (lbMainItems.ItemsSource as List <Item>).Remove(i);

            RefreshPanel();
        }
Exemplo n.º 2
0
        public static bool UpdateData(FormedBasket x)
        {
            BaseDataBase._NonQuery("delete from FormedBasket_Item where FormedBasket_Item.FormedBasketID = " + x.Id);
            bool b = BaseDataBase._StoredProcedure("sp_Update_FormedBasket"
                                                   , new SqlParameter("@Id", x.Id)
                                                   , new SqlParameter("@Name", x.Name)
                                                   , new SqlParameter("@IsActive", x.IsActive)
                                                   , new SqlParameter("@IsUrgent", x.IsUrgent)
                                                   , new SqlParameter("@Notes", x.Notes)
                                                   , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID));

            foreach (var item in x.FormedBasketItems)
            {
                if (item.FormedBasket == null)
                {
                    item.FormedBasket = x;
                }
                FormedBasket_Item.InsertData(item);
            }
            if (x.id.HasValue)
            {
                FormedBasket_Sector.SaveFormedBasketSectors(x);
            }
            return(b);
        }
Exemplo n.º 3
0
 public static bool DeleteData(FormedBasket_Item x)
 {
     FormedBasket_Item.UpdateData(x);
     return(BaseDataBase._StoredProcedure("sp_Delete_FormedBasket_Item"
                                          , new SqlParameter("@FormedBasketID", x.FormedBasket.Id)
                                          , new SqlParameter("@ItemID", x.RelatedItem.Id)));
 }
Exemplo n.º 4
0
 public static bool UpdateData(FormedBasket_Item x)
 {
     return(BaseDataBase._StoredProcedure("sp_Update_FormedBasket_Item"
                                          , new SqlParameter("@FormedBasketID", x.FormedBasket.Id)
                                          , new SqlParameter("@ItemID", x.RelatedItem.Id)
                                          , new SqlParameter("@Quantity", x.Quantity)
                                          , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID)));
 }
        private void btnDelItem_Click(object sender, RoutedEventArgs e)
        {
            if (dgSelectedItems.SelectedIndex != -1)
            {
                txtSearch.Text = string.Empty;
                FormedBasket_Item s = dgSelectedItems.SelectedItem as FormedBasket_Item;
                var i = s.RelatedItem;

                (lbMainItems.ItemsSource as List <Item>).Add(i);
                (dgSelectedItems.ItemsSource as List <FormedBasket_Item>).Remove(s);

                RefreshPanel();
            }
        }
Exemplo n.º 6
0
        internal static List <FormedBasket> GetFormedBasketByFamilyID(int familyID)
        {
            List <FormedBasket> xx  = new List <FormedBasket>();
            SqlConnection       con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand          com = new SqlCommand("sp_Get_All_FormedBasketByFamilyID", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            com.Parameters.Add(new SqlParameter("@FamilyID", familyID));
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    FormedBasket x = new FormedBasket();

                    if (!(rd["Id"] is DBNull))
                    {
                        x.Id = int.Parse(rd["Id"].ToString());
                    }
                    x.Name = rd["Name"].ToString();
                    if (!(rd["IsActive"] is DBNull))
                    {
                        x.IsActive = bool.Parse(rd["IsActive"].ToString());
                    }
                    if (!(rd["IsUrgent"] is DBNull))
                    {
                        x.IsUrgent = bool.Parse(rd["IsUrgent"].ToString());
                    }
                    x.Notes = rd["Notes"].ToString();
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                    x.FormedBasketItems = FormedBasket_Item.GetAllBasket_ItemByBasket(x);
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }
Exemplo n.º 7
0
        public static FormedBasket GetItemByID(int id)
        {
            FormedBasket  x   = new FormedBasket();
            SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand    com = new SqlCommand("sp_Get_ID_FormedBasket", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr = new SqlParameter("@ID", id);

            com.Parameters.Add(pr);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    if (!(rd["Id"] is DBNull))
                    {
                        x.Id = int.Parse(rd["Id"].ToString());
                    }
                    x.Name = rd["Name"].ToString();
                    if (!(rd["IsActive"] is DBNull))
                    {
                        x.IsActive = bool.Parse(rd["IsActive"].ToString());
                    }
                    if (!(rd["IsUrgent"] is DBNull))
                    {
                        x.IsUrgent = bool.Parse(rd["IsUrgent"].ToString());
                    }
                    x.Notes = rd["Notes"].ToString();
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }

                    x.FormedBasketItems = FormedBasket_Item.GetAllBasket_ItemByBasket(x);
                }
                rd.Close();
            }
            catch
            {
                x = null;
            }
            finally
            {
                con.Close();
            }
            return(x);
        }
Exemplo n.º 8
0
        public static FormedBasket_Item GetBasket_ItemByID(int FormedBasketID, int ItemID)
        {
            FormedBasket_Item x   = new FormedBasket_Item();
            SqlConnection     con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand        com = new SqlCommand("sp_Get_ID_FormedBasket_Item", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr1 = new SqlParameter("@FormedBasketID", FormedBasketID);

            com.Parameters.Add(pr1);
            SqlParameter pr2 = new SqlParameter("@ItemID", ItemID);

            com.Parameters.Add(pr2);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    if (!(rd["FormedBasketID"] is DBNull))
                    {
                        x.FormedBasket = FormedBasket.GetItemByID(int.Parse(rd["FormedBasketID"].ToString()));
                    }
                    if (!(rd["ItemID"] is DBNull))
                    {
                        x.RelatedItem = Item.GetItemByID(int.Parse(rd["ItemID"].ToString()));
                    }
                    if (!(rd["Quantity"] is DBNull))
                    {
                        x.Quantity = double.Parse(rd["Quantity"].ToString());
                    }
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                }
                rd.Close();
            }
            catch
            {
                x = null;
            }
            finally
            {
                con.Close();
            }
            return(x);
        }
Exemplo n.º 9
0
        public static List <FormedBasket_Item> GetAllBasket_ItemByBasket(FormedBasket FormedBasket)
        {
            List <FormedBasket_Item> xx  = new List <FormedBasket_Item>();
            SqlConnection            con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand com = new SqlCommand("sp_Get_All_FormedBasket_Item_ByFormedBasketID", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr1 = new SqlParameter("@FormedBasketID", FormedBasket.Id);

            com.Parameters.Add(pr1);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    FormedBasket_Item x = new FormedBasket_Item();
                    x.FormedBasket = FormedBasket;
                    if (!(rd["ItemID"] is DBNull))
                    {
                        x.RelatedItem = Item.GetItemByID(int.Parse(rd["ItemID"].ToString()));
                    }
                    if (!(rd["Quantity"] is DBNull))
                    {
                        x.Quantity = double.Parse(rd["Quantity"].ToString());
                    }
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }
Exemplo n.º 10
0
        public static bool InsertData(FormedBasket x)
        {
            x.Id = BaseDataBase._StoredProcedureReturnable("sp_Add_FormedBasket"
                                                           , new SqlParameter("@Id", System.Data.SqlDbType.Int)
                                                           , new SqlParameter("@Name", x.Name)
                                                           , new SqlParameter("@IsActive", x.IsActive)
                                                           , new SqlParameter("@IsUrgent", x.IsUrgent)
                                                           , new SqlParameter("@Notes", x.Notes)
                                                           , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID));

            foreach (var item in x.FormedBasketItems)
            {
                if (item.FormedBasket == null)
                {
                    item.FormedBasket = x;
                    FormedBasket_Item.InsertData(item);
                }
            }
            if (x.id.HasValue)
            {
                FormedBasket_Sector.SaveFormedBasketSectors(x);
            }
            return(x.Id.HasValue);
        }