private void GenerateConsignmentResultsForm_Load(object sender, EventArgs e)
        {
            //set title
            labelTitleDisplay.Text = "Checking Lost Items for Consignment Period " +
                                     ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(consignmentPeriod);

            //load unsold - items data from the period
            context.Items.Where(item =>
                                item.ItemStatus == ConsignmentStoreBusinessLogic.ITEM_STATUS_UNSOLD &&
                                item.ConsignedDate.Month == consignmentPeriod % 100 &&
                                item.ConsignedDate.Year == consignmentPeriod / 100).Load();

            //setup datagridview
            FormHelper.InitializeDataGridViewSettings(dataGridViewItems);

            //binding to dataGridView
            dataGridViewItems.DataSource = context.Items.Local.ToBindingList();
            dataGridViewItems.Columns["SoldItem"].Visible  = false;
            dataGridViewItems.Columns["Employee"].Visible  = false;
            dataGridViewItems.Columns["Consignor"].Visible = false;

            //toggle status of item by double-click
            dataGridViewItems.CellDoubleClick += ToggleItemStatusLostOrUnsold;

            //filter by consignorId
            textBoxSearch.TextChanged += SearchByConsignorId;

            //button finish is clicked
            buttonFinishGenerateConsignmentResults.Click += GenerateConsignmentResults;
        }
        private void GenerateConsignmentResults(object sender, EventArgs e)
        {
            //change all local items that have status "unsold" to "returned" and save to database
            foreach (var item in context.Items.Local.Where(i =>
                                                           i.ItemStatus.Trim() == ConsignmentStoreBusinessLogic.ITEM_STATUS_UNSOLD))
            {
                item.ItemStatus = ConsignmentStoreBusinessLogic.ITEM_STATUS_RETURNED;
            }

            context.SaveChanges();//save to database

            //generate consignment results
            if (ConsignmentStoreBusinessLogic.GenerateConsignmentResultsForPeriod(consignmentPeriod))
            {
                FormHelper.ShowInfoMessageBox("Consignment Results for Period " +
                                              ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(consignmentPeriod) + " are creared!");

                //success then close the form
                Close();
            }
            else
            {
                FormHelper.ShowErrorMessageBox("Consignment Results for Period " +
                                               ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(consignmentPeriod) + " cannot creared. Please try again!");
            }
        }
        private string GetConsignmentResultDetails(ConsignmentResult result)
        {
            if (result == null)
            {
                return("");
            }

            stringBuilder.Clear();
            stringBuilder.AppendLine(string.Format("{0,-20} {1}", "Consignor Id",
                                                   result.Consignor.ConsignorId));
            stringBuilder.AppendLine(string.Format("{0,-20} {1}", "Consignor Name",
                                                   result.Consignor.ConsignorName.Trim()));
            stringBuilder.AppendLine(string.Format("{0,-20} {1}", "Consignor DOB",
                                                   ((DateTime)result.Consignor.ConsignorDOB).ToString("dd MMMM yyyy")));
            stringBuilder.AppendLine(string.Format("{0,-20} {1}", "Consignor Phone",
                                                   result.Consignor.ConsignorPhone.Trim()));
            stringBuilder.AppendLine(string.Format("{0,-20} {1}", "Consignor Email",
                                                   result.Consignor.ConsignorEmail.Trim()));
            stringBuilder.AppendLine(string.Format("{0,-20} {1}", "Consignor Period",
                                                   ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(result.ConsignmentPeriod)));
            stringBuilder.AppendLine(string.Format("{0,-20} {1:n0}", "Returned Items",
                                                   result.NumberOfReturnedItems));
            stringBuilder.AppendLine(string.Format("{0,-20} {1:c}", "Value Items",
                                                   result.TotalValueOfReturnedItems));
            stringBuilder.AppendLine(string.Format("{0,-20} {1:c}", "Consignment Result",
                                                   result.TotalValueReceivedByConsignor));

            return(stringBuilder.ToString());
        }
Esempio n. 4
0
        private void UserControlManageConsignmentResults_Load(object sender, EventArgs e)
        {
            //add consignment periods to combox box (format: month/year)
            foreach (var period in context.ConsignmentSummaries.Local.ToList())
            {
                comboBoxConsignmentPeriods.Items.Add(
                    ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(period.ConsignmentPeriod));
            }

            //binding datagridview
            FormHelper.InitializeDataGridViewSettings(dataGridViewConsignmentResults);
            FormHelper.InitializeDataGridViewSettings(dataGridViewConsignmentSummaries);

            dataGridViewConsignmentResults.DataSource = context.ConsignmentResults.Local.ToBindingList();//binding to dataGridView
            dataGridViewConsignmentResults.Columns["ConsignmentSummary"].Visible = false;
            dataGridViewConsignmentResults.Columns["Consignor"].Visible          = false;
            dataGridViewConsignmentResults.Columns["Employee"].Visible           = false;
            foreach (int colNum in new int[] { 3, 5, 7, 8 })// format money
            {
                dataGridViewConsignmentResults.Columns[colNum].DefaultCellStyle.Format    = "N2";
                dataGridViewConsignmentResults.Columns[colNum].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            }

            dataGridViewConsignmentSummaries.DataSource = context.ConsignmentSummaries.Local.ToBindingList();//binding to dataGridView
            dataGridViewConsignmentSummaries.Columns["ConsignmentResults"].Visible = false;

            foreach (int colNum in new int[] { 1, 2, 4, 7, 9 })// format number
            {
                dataGridViewConsignmentSummaries.Columns[colNum].DefaultCellStyle.Format = "N0";
            }

            foreach (int colNum in new int[] { 3, 5, 6, 8, 10, 11 })// format money
            {
                dataGridViewConsignmentSummaries.Columns[colNum].DefaultCellStyle.Format    = "N2";
                dataGridViewConsignmentSummaries.Columns[colNum].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            }


            //combobox
            comboBoxConsignmentPeriods.SelectedIndexChanged += UpdateConsignmentPeriod;

            //button generate consignment results
            buttonGenerateConsignmentResults.Click += GenerateConsignmentResults;
        }
Esempio n. 5
0
        private void GenerateConsignmentResults(object sender, EventArgs e)
        {
            //consignment period must
            //1. must be greater than the largest consignmentPeriod (e.g. current is 201901)
            //2. must less than current month (e.g. 201904)
            //valid consignmentPeriods are  201902, 201903

            //convert selected item in combobox to consignmentPeriod
            int consignmentPeriod = ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromString(
                (int)numericUpDownMonth.Value + "/" + (int)numericUpDownYear.Value);

            int upLimitConsignmentPeriod = ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromString(
                DateTime.Now.Month + "/" + DateTime.Now.Year);

            int downLimitConsignmentPeriod = context.ConsignmentSummaries.Max(summary => summary.ConsignmentPeriod);

            if (!ConsignmentStoreBusinessLogic.ValidateConsignmentPeriod(consignmentPeriod))
            {
                FormHelper.ShowErrorMessageBox("Period must greater than " +
                                               ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(downLimitConsignmentPeriod) + " and less than " +
                                               ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(upLimitConsignmentPeriod));
                return;
            }

            //Checking lost items
            GenerateConsignmentResultsForm generateConsignmentResultsForm = new GenerateConsignmentResultsForm(consignmentPeriod);

            generateConsignmentResultsForm.ShowDialog();
            generateConsignmentResultsForm.Dispose();

            //Load combobox again
            comboBoxConsignmentPeriods.Items.Clear();
            //add consignment periods to combox box (format: month/year)
            foreach (var period in context.ConsignmentSummaries.Local.ToList())
            {
                comboBoxConsignmentPeriods.Items.Add(
                    ConsignmentStoreBusinessLogic.GetConsignmentPeriodFromInt(period.ConsignmentPeriod));
            }
        }