Пример #1
0
        /// <summary>
        /// Click event for the Select Master button
        /// </summary>
        private void btn_SelectMaster_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = Wizard.defaultpath;
            ofd.Title            = "Select Master Database";
            ofd.Filter           = "SecondSight Databases (*.ssd)|*.ssd|All Files (*.*)|*.*";
            ofd.CheckFileExists  = true;
            ofd.Multiselect      = false;
            ofd.DefaultExt       = ".ssd";

            //Process the open file dialog
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                SSDataBase ssdbt = new SSDataBase();

                //If the file name is the same as the "current" database's filename, that means the user wants to select the
                //database currently open in the main program.  Don't attempt to open that one a second time.  Otherwise
                //attempt to open the selected database
                if (ofd.FileName == Wizard.currentdb.MyPath)
                {
                    Wizard.masterdb = Wizard.currentdb; //Set the master to the currently open db
                }
                else
                {
                    try
                    { //Attempt to open the selected database
                        ssdbt.OpenDB(ofd.FileName);
                    }
                    catch
                    { //Not a valid secondsight database
                        MessageBox.Show("The selected file is not a valid SecondSight database and cannot be used as the master database for a merge.",
                                        "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }
                    Wizard.masterdb = ssdbt; //Set the master to the newly selected db
                }

                //Get the info for the database
                string tname;
                string tloc;
                System.Data.DataTable dt = new System.Data.DataTable();
                try
                {
                    Wizard.masterdb.GetTable(dt, SSTable.DBInfo);
                    tname = Convert.ToString(dt.Rows[0][0]);
                    tloc  = Convert.ToString(dt.Rows[0][1]);
                }
                catch
                {
                    MessageBox.Show("The selected file is not a valid SecondSight database and cannot be used as the master database for a merge.",
                                    "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                lb_CurrentMaster.Text = "Master Database: " + tname + " (" + tloc + ")";
            }
        }
        private DataTable dt_Add_MergeTable;        //Data table that holds the Merge subset of inventory in a Merge database

        /// <summary>
        /// Performs additional configuration on controls, based on the information set by LoadPrefs
        /// </summary>
        private void ConfigureComponent()
        {
            dt_Add_MergeTable   = new DataTable();
            dt_V_DispensedTable = new DataTable();
            LoadPrefs();

            Size            = new System.Drawing.Size(GuiPrefs.Width, GuiPrefs.Height);
            LastWindowState = WindowState;

            //Set maximized state of the program
            if (GuiPrefs.Maximized)
            {
                WindowState = FormWindowState.Maximized;
            }
            else
            {
                WindowState = FormWindowState.Normal;
            }

            #region Add New Item tabpage config
            bs_Add_InventorySource            = new BindingSource();
            bs_Add_InventorySource.DataSource = Mydb.InvResults;
            dgv_Add_InventoryView.ConfigureDGV();
            dgv_Add_InventoryView.Columns["Score"].Visible         = false;
            dgv_Add_InventoryView.Columns["DateDispensed"].Visible = false;
            dgv_Add_InventoryView.DataSource = bs_Add_InventorySource;

            foreach (DataGridViewColumn col in dgv_Add_InventoryView.Columns)
            {
                col.SortMode = DataGridViewColumnSortMode.Automatic;
            }
            #endregion

            #region Search tabpage config
            dgv_S_SearchResults.ConfigureDGV();
            dgv_S_SearchResults.Columns["DateDispensed"].Visible = false;
            dgv_S_SearchResults.DataSource = Mydb.DBResults;
            dgv_S_Distance.ConfigureDGV();
            dgv_S_Distance.Columns["DateDispensed"].Visible = false;
            dgv_S_Distance.DataSource = Mydb.DBResults;
            dgv_S_Closeup.ConfigureDGV();
            dgv_S_Closeup.Columns["DateDispensed"].Visible = false;
            dgv_S_Closeup.DataSource = Mydb.DBResultsAux;
            #endregion

            #region Dispense tabpage config
            dispenseTable = new DataTable();
            deleteTable   = new DataTable();
            #endregion

            #region View Inventory tabpage config
            bs_V_SearchByField              = new BindingList <KeyValuePair <string, string> >();
            bs_V_InventorySource            = new BindingSource();
            bs_V_InventorySource.DataSource = Mydb.InvResults;

            bs_V_SearchByField.Add(new KeyValuePair <string, string>("SKU", "SKU"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OD Sphere", "SphereOD"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OD Cylinder", "CylinderOD"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OD Axis", "AxisOD"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OD Add", "AddOD"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OS Sphere", "SphereOS"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OS Cylinder", "CylinderOS"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OS Axis", "AxisOS"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("OS Add", "AddOS"));
            bs_V_SearchByField.Add(new KeyValuePair <string, string>("Date Added", "DateAdded"));

            dgv_V_InventoryView.ConfigureDGV();
            dgv_V_InventoryView.Columns["Score"].Visible         = false;
            dgv_V_InventoryView.Columns["DateDispensed"].Visible = false;
            dgv_V_InventoryView.DataSource   = bs_V_InventorySource;
            cb_V_SearchByField.DataSource    = bs_V_SearchByField;
            cb_V_SearchByField.DisplayMember = "Key";
            cb_V_SearchByField.ValueMember   = "Value";
            cb_V_SearchByField.SelectedIndex = 0;
            cb_V_SearchIn.SelectedIndex      = 0;
            foreach (DataGridViewColumn col in dgv_V_InventoryView.Columns)
            {
                col.SortMode = DataGridViewColumnSortMode.Automatic;
            }

            #endregion

            #region Reports tabpage config
            bs_R_FullLists = new BindingSource();
            bs_R_Summaries = new BindingSource();

            cb_R_ReportSource.SelectedIndex = 0;
            cb_R_ReportType.SelectedIndex   = 0;
            cb_R_GroupBy.SelectedIndex      = 0;

            dgv_R_FullLists.ConfigureDGV();
            dgv_R_FullLists.Columns["Score"].Visible         = false;
            dgv_R_FullLists.Columns["DateDispensed"].Visible = false;
            foreach (DataGridViewColumn col in dgv_R_FullLists.Columns)
            {
                col.SortMode = DataGridViewColumnSortMode.Automatic;
            }

            dgv_R_FullLists.DataSource = bs_R_FullLists;
            dgv_R_Summaries.DataSource = bs_R_Summaries;

            ZedGraph.GraphPane gpane = zed_R_Chart.GraphPane;
            gpane.Title.Text = "Report Results";
            #endregion


            //A db was opened last time, attempt to open it
            if (GuiPrefs.OpenMostRecentDB)
            {
                try
                {
                    Mydb.OpenDB(GuiPrefs.OpenDBPath); //Valid SecondSight database
                }
                catch
                {
                    return; //Fail quietly since this happens at startup
                }

                UpdateAfterOpenDB();
            }
        }
Пример #3
0
        //Click event for Add Databases button
        //Opens an OpenFileDialog for user to browse for merge-able database files,
        //verifies them, and adds them to the list
        private void btn_AddDatabases_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = mvars.defaultDBPath;
            ofd.Title = "Select Databases to Merge";
            ofd.Filter = "SecondSight Partial Databases (*.ssp)|*.ssp|All Files (*.*)|*.*";
            ofd.CheckFileExists = true;
            ofd.Multiselect = true;
            ofd.DefaultExt = ".ssp";

            //Process selected files if user didn't cancel
            if( ofd.ShowDialog() == DialogResult.OK ) {
                string errmsg = ""; //Holds composite error message
                Cursor.Current = Cursors.WaitCursor;

                //For each file selected, open the database, grab the DB info, check DB info against
                //master DB info and exclude if they don't match (display error message after batch processing)
                //check for mergeDB-specific info (the label and the assigned min/max SKUs) and include it in the
                //list box entry if available
                foreach (string fname in ofd.FileNames) {
                    SSDataBase ssdb = new SSDataBase();
                    DataTable dt = new DataTable();
                    string[] info = new string[3];

                    if (fname != mvars.Masterdb.MyPath) {
                        try {
                            ssdb.OpenDB(fname);
                            ssdb.GetTable(dt, SSTable.DBInfo);
                            info[0] = dt.Rows[0][0].ToString();
                            info[1] = dt.Rows[0][1].ToString();
                            info[2] = String.Format("{0:MM/dd/yyyy}", dt.Rows[0][2]);
                        } catch { //An exception will be thrown if something
                            info[0] = info[1] = info[2] = "Unknown";
                        }

                        //If the database info doesn't match, compile an error message,
                        //otherwise include the info in the listbox and mvars
                        if( (info[0] != mvars.Masterdbname) ||
                            (info[1] != mvars.Masterdblocation) ||
                            (info[2] != mvars.Masterdbdate)) {
                            errmsg += System.IO.Path.GetFileName(fname) + ": " + info[0] + " (" + info[1] + "), Created on " + info[2] + "\n";
                        } else {
                            mvars.mergeDBs.Add(ssdb);
                            string ts = info[0] + " (" + info[1] + ")"; //Compile the listbox item string
                            try {
                                dt.Reset();
                                ssdb.GetTable(dt, SSTable.MergeInfo);
                                ts += " - For " + dt.Rows[0][0].ToString() + " - SKU Assignment: " + Convert.ToInt16(dt.Rows[0][1]) +
                                    " to " + Convert.ToInt16(dt.Rows[0][2]);
                            }
                            catch {
                                ts += " - No additional information";
                            }

                            lbox_DatabasesToMerge.Items.Add(ts);
                        }
                        try {ssdb.CloseDB();} catch{} //Attempt to close the current merge database
                    }
                }

                Cursor.Current = Cursors.Default;

                //Display the error message if any databases were excluded
                if(errmsg.Length > 0) {
                    errmsg = "The following files you selected are either not valid SecondSight database files or are " +
                        "SecondSight databases that do not match the master database.\n\n" + errmsg + "\n\nThese files " +
                        "will not be included in the merge.";
                    MessageBox.Show(errmsg, "Some Files Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //else {
                //    MessageBox.Show("The selected databases were successfully merged into the selected master.", "Merge Successful",
                //        MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
            }
        }
Пример #4
0
        //Click event for Select Master button
        //Opens an open file dialog and switches the currently selected master database
        //after verifying the selection is valid.
        private void btn_SelectMaster_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = mvars.defaultDBPath;
            ofd.Title = "Select Master Database";
            ofd.Filter = "SecondSight Databases (*.ssd)|*.ssd|All Files (*.*)|*.*";
            ofd.CheckFileExists = true;
            ofd.Multiselect = false;
            ofd.DefaultExt = ".ssd";

            //Process the open file dialog
            if (ofd.ShowDialog() == DialogResult.OK) {
                SSDataBase ssdbt = new SSDataBase();
                try {
                    ssdbt.OpenDB(ofd.FileName);
                } catch { //Not a valid secondsight database
                    MessageBox.Show("The selected file is not a valid SecondSight database and cannot be used as the master database for a merge.",
                        "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                //Get the info for the new database
                string tname = mvars.Masterdbname;
                string tloc = mvars.Masterdblocation;
                string tdate = mvars.Masterdbdate;
                DataTable dt = new DataTable();
                try {
                    ssdbt.GetTable(dt, SSTable.DBInfo);
                    mvars.Masterdbname = Convert.ToString(dt.Rows[0][0]);
                    mvars.Masterdblocation = Convert.ToString(dt.Rows[0][1]);
                    mvars.Masterdbdate = String.Format("{0:MM/dd/yyyy}", dt.Rows[0][2]);
                } catch {
                    MessageBox.Show("The selected file is not a valid SecondSight database and cannot be used as the master database for a merge.",
                        "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    mvars.Masterdbname = tname;
                    mvars.Masterdblocation = tloc;
                    mvars.Masterdbdate = tdate;
                    return;
                }

                //Close the previously selected master database, switch the pointer to the new one and
                //update the label on the control
                if(mvars.Masterdb.IsOpen()) {
                    try {
                        mvars.Masterdb.CloseDB();
                    } catch {}
                }
                mvars.Masterdb = ssdbt;
                lb_CurrentMaster.Text = "Master Database: " + mvars.Masterdbname + " (" + mvars.Masterdblocation + ")";
            }
        }
Пример #5
0
        //Click event for Select Master button
        //Opens an open file dialog and switches the currently selected master database
        //after verifying the selection is valid.
        private void btn_SelectMaster_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = mvars.defaultDBPath;
            ofd.Title            = "Select Master Database";
            ofd.Filter           = "SecondSight Databases (*.ssd)|*.ssd|All Files (*.*)|*.*";
            ofd.CheckFileExists  = true;
            ofd.Multiselect      = false;
            ofd.DefaultExt       = ".ssd";

            //Process the open file dialog
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                SSDataBase ssdbt = new SSDataBase();
                try
                {
                    ssdbt.OpenDB(ofd.FileName);
                }
                catch
                { //Not a valid secondsight database
                    MessageBox.Show("The selected file is not a valid SecondSight database and cannot be used as the master database for a merge.",
                                    "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                //Get the info for the new database
                string    tname = mvars.Masterdbname;
                string    tloc  = mvars.Masterdblocation;
                string    tdate = mvars.Masterdbdate;
                DataTable dt    = new DataTable();
                try
                {
                    ssdbt.GetTable(dt, SSTable.DBInfo);
                    mvars.Masterdbname     = Convert.ToString(dt.Rows[0][0]);
                    mvars.Masterdblocation = Convert.ToString(dt.Rows[0][1]);
                    mvars.Masterdbdate     = String.Format("{0:MM/dd/yyyy}", dt.Rows[0][2]);
                }
                catch
                {
                    MessageBox.Show("The selected file is not a valid SecondSight database and cannot be used as the master database for a merge.",
                                    "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    mvars.Masterdbname     = tname;
                    mvars.Masterdblocation = tloc;
                    mvars.Masterdbdate     = tdate;
                    return;
                }

                //Close the previously selected master database, switch the pointer to the new one and
                //update the label on the control
                if (mvars.Masterdb.IsOpen())
                {
                    try
                    {
                        mvars.Masterdb.CloseDB();
                    }
                    catch { }
                }
                mvars.Masterdb        = ssdbt;
                lb_CurrentMaster.Text = "Master Database: " + mvars.Masterdbname + " (" + mvars.Masterdblocation + ")";
            }
        }
Пример #6
0
        //Click event for Add Databases button
        //Opens an OpenFileDialog for user to browse for merge-able database files,
        //verifies them, and adds them to the list
        private void btn_AddDatabases_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = mvars.defaultDBPath;
            ofd.Title            = "Select Databases to Merge";
            ofd.Filter           = "SecondSight Partial Databases (*.ssp)|*.ssp|All Files (*.*)|*.*";
            ofd.CheckFileExists  = true;
            ofd.Multiselect      = true;
            ofd.DefaultExt       = ".ssp";

            //Process selected files if user didn't cancel
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string errmsg = ""; //Holds composite error message
                Cursor.Current = Cursors.WaitCursor;

                //For each file selected, open the database, grab the DB info, check DB info against
                //master DB info and exclude if they don't match (display error message after batch processing)
                //check for mergeDB-specific info (the label and the assigned min/max SKUs) and include it in the
                //list box entry if available
                foreach (string fname in ofd.FileNames)
                {
                    SSDataBase ssdb = new SSDataBase();
                    DataTable  dt   = new DataTable();
                    string[]   info = new string[3];

                    if (fname != mvars.Masterdb.MyPath)
                    {
                        try
                        {
                            ssdb.OpenDB(fname);
                            ssdb.GetTable(dt, SSTable.DBInfo);
                            info[0] = dt.Rows[0][0].ToString();
                            info[1] = dt.Rows[0][1].ToString();
                            info[2] = String.Format("{0:MM/dd/yyyy}", dt.Rows[0][2]);
                        }
                        catch
                        { //An exception will be thrown if something
                            info[0] = info[1] = info[2] = "Unknown";
                        }

                        //If the database info doesn't match, compile an error message,
                        //otherwise include the info in the listbox and mvars
                        if ((info[0] != mvars.Masterdbname) ||
                            (info[1] != mvars.Masterdblocation) ||
                            (info[2] != mvars.Masterdbdate))
                        {
                            errmsg += System.IO.Path.GetFileName(fname) + ": " + info[0] + " (" + info[1] + "), Created on " + info[2] + "\n";
                        }
                        else
                        {
                            mvars.mergeDBs.Add(ssdb);
                            string ts = info[0] + " (" + info[1] + ")"; //Compile the listbox item string
                            try
                            {
                                dt.Reset();
                                ssdb.GetTable(dt, SSTable.MergeInfo);
                                ts += " - For " + dt.Rows[0][0].ToString() + " - SKU Assignment: " + Convert.ToInt16(dt.Rows[0][1]) +
                                      " to " + Convert.ToInt16(dt.Rows[0][2]);
                            }
                            catch
                            {
                                ts += " - No additional information";
                            }

                            lbox_DatabasesToMerge.Items.Add(ts);
                        }
                        try
                        { ssdb.CloseDB(); }
                        catch { } //Attempt to close the current merge database
                    }
                }

                Cursor.Current = Cursors.Default;

                //Display the error message if any databases were excluded
                if (errmsg.Length > 0)
                {
                    errmsg = "The following files you selected are either not valid SecondSight database files or are " +
                             "SecondSight databases that do not match the master database.\n\n" + errmsg + "\n\nThese files " +
                             "will not be included in the merge.";
                    MessageBox.Show(errmsg, "Some Files Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //else {
                //    MessageBox.Show("The selected databases were successfully merged into the selected master.", "Merge Successful",
                //        MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
            }
        }