private void Button_Add_Click_1(object sender, RoutedEventArgs e)
        {
            ComboBox_Quantity.Text = "";
            TextBox_Search.Clear();
            ComboBox_ItemDescription.Text = "";
            ComboBox_Quantity.Items.Clear();

            itemselected_source.Clear();
            status = userContent.New;

            refresh();
        }
        private void DataGrid_LogBook_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataGrid_LogBook.SelectedItem == null)
            {
                return;
            }
            var selectedDetails = DataGrid_LogBook.SelectedItem as LogBook;

            RequestNo         = selectedDetails.RequestNo;
            ItemCode_Retrieve = selectedDetails.ItemCode;
            ItemQuantity      = selectedDetails.ItemQuantity;
            status            = userContent.Selectdatagrid;
        }
        private async void Button_Retrieve_Click(object sender, RoutedEventArgs e)
        {
            string  query;
            DataSet ds;
            DataRow drow;
            string  itemCode2;
            string  remarks;
            string  remarks2;

            try
            {
                query = $@"Select Id,Quantity,Remarks from ItemDetailss where Id='{ItemCode_Retrieve}'";
                ds    = await dc.Connection1Async(query);

                drow = ds.Tables[0].Rows[0];


                itemCode2   = drow.ItemArray.GetValue(0).ToString();
                AddQuantity = int.Parse(drow.ItemArray.GetValue(1).ToString());
                remarks2    = drow.ItemArray.GetValue(2).ToString();


                int addQuantity1;
                addQuantity1 = ItemQuantity + AddQuantity;
                remarks      = "The item: " + ItemCode_Retrieve + " , " + ItemQuantity + " was recorved by " + fullName + " with an ID No. " + userId + " as of " + date + " - " + time.ToString();

                query = $@"update ItemDetailss set Quantity = '{addQuantity1}' , Remarks = '{remarks2}{remarks}' where Id = '{ItemCode_Retrieve}'";
                dc.Connection2(query);

                query = $@"Insert into 
RemarksMessage(Id,Remarks)
values ('{ItemCode_Retrieve}','{remarks}') ";
                dc.Connection2(query);

                query = $@"Delete From RequestorVieww where  RequestorNo='{RequestNo}'";
                dc.Connection2(query);
                Loading_User.Visibility = Visibility.Visible;
                Icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.Feather;
                TextBlock_Message.FontSize = 13;
                TextBlock_Message.Text     = "The item: " + ItemCode_Retrieve + " , " + ItemQuantity + " was recorved by " + fullName + " with an ID No. " + userId + " as of " + date + " - " + time.ToUpper();

                status = userContent.itemRecovery;
            }
            catch
            {
                Loading_User.Visibility = Visibility.Visible;
                Icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.DiskAlert;
                TextBlock_Message.Text = "Item doesn't exist".ToUpper();
            }
        }
        private async void Button_Search_Click(object sender, RoutedEventArgs e)
        {
            string  query;
            DataSet ds;
            DataRow drow;

            dc = new database_connection();

            try
            {
                query = $@"
select RequestorNo
,ItemDescription
,Quantity
,Unit
,CONVERT(VARCHAR(12), DateIssued, 107) AS [Mon DD, YYYY]
,Convert(VARCHAR(12), Timee, 0 ) as output, 0 as style
,ItemCode
,IdOfRequestor
from RequestorVieww
where (RequestorNo like '%{TextBox_Search.Text}%' or ItemDescription like '%{TextBox_Search.Text}%' or ItemCode like '%{TextBox_Search.Text}%' or DateIssued like '%{TextBox_Search.Text}%') and IdOfRequestor like '%{userId}%'
";
                Loading_User.Visibility = Visibility.Visible;
                ds = await dc.Connection1Async(query);

                Loading_User.Visibility = Visibility.Collapsed;

                int ctr, total;
                total = ds.Tables[0].Rows.Count;

                itemselected_source.Clear();

                for (ctr = 0; ctr < total; ctr++)
                {
                    drow = ds.Tables[0].Rows[ctr];
                    itemselected_source.Add(new LogBook
                    {
                        RequestNo = drow.ItemArray.GetValue(0).ToString()
                        ,
                        ItemDescription = drow.ItemArray.GetValue(1).ToString()
                        ,
                        ItemQuantity = int.Parse(drow.ItemArray.GetValue(2).ToString())
                        ,
                        ItemUnit = drow.ItemArray.GetValue(3).ToString()
                        ,
                        Datee = drow.ItemArray.GetValue(4).ToString()
                        ,
                        Timee = drow.ItemArray.GetValue(5).ToString()
                        ,
                        ItemCode = drow.ItemArray.GetValue(7).ToString()
                    });
                }
                status = userContent.search;
            }
            catch (Exception ex)
            {
                Loading_User.Visibility = Visibility.Visible;
                Icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.MessageAlert;
                TextBlock_Message.Text = ex.Message.ToUpper();
            }
        }
        private async void Button_Save_Click_1(object sender, RoutedEventArgs e)
        {
            dc = new database_connection();
            string query;


            if (status == userContent.New)
            {
                string requestorNo = await GetNewReferenceNumber();

                if (ComboBox_ItemDescription.Text == "" | ComboBox_Quantity.Text == "")
                {
                    Loading_User.Visibility = Visibility.Visible;
                    Icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.AccountCheck;
                    TextBlock_Message.Text = "Complete the Information".ToUpper();
                }

                else
                {
                    try
                    {
                        a     = SubtractQuantity - int.Parse(ComboBox_Quantity.Text);
                        b     = a * price;
                        c     = int.Parse(ComboBox_Quantity.Text) * price;
                        query = $@"UPDATE ItemDetailss
SET Quantity ='{a}', TotalCost = '{b}'
WHERE ItemDescription='{ComboBox_ItemDescription.Text}'";
                        dc.Connection2(query);
                        query = $@"Insert Into
RequestorVieww(RequestorNo,
NameOfRequestor,
IdOfRequestor,
Department,
ItemCode,
ItemDescription,
Quantity,
Unit,
DateIssued,
Timee,
Price,
TotalCost,
Monthh,
Yearr
)
Values('{requestorNo}','{fullName}'
,'{userId}','{department}'
,'{itemCode}','{ComboBox_ItemDescription.Text}'
,'{ComboBox_Quantity.Text}','{unit}'
,'{date}','{time}'
,'{price}','{c}'
,'{month}','{year}')";
                        dc.Connection2(query);

                        ComboBox_ItemDescription.Text = "";
                        ComboBox_Quantity.Text        = "";
                        Loading_User.Visibility       = Visibility.Visible;
                        Icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.ContentSave;
                        TextBlock_Message.Text = "Request Saved".ToUpper();
                        status = userContent.Saved;
                    }
                    catch
                    {
                        Loading_User.Visibility = Visibility.Visible;
                        Icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.CartOff;
                        TextBlock_Message.Text = "Out Of Stock".ToUpper();
                    }
                }
            }
            else
            {
                Loading_User.Visibility = Visibility.Visible;
                Icon.Kind = MahApps.Metro.IconPacks.PackIconMaterialKind.NewBox;
                TextBlock_Message.Text = "Please click the new record".ToUpper();
            }
        }