Beispiel #1
0
        protected void Page_Init(object sender, EventArgs e)
        {
            mm = (MinMaster)Master;

            if (!(Session["Summary"] is DataTable))
            {
                HierarchyNavTable baseNavTable = ((TreeControl)(mm.SysDriver.MainPanel.controls[0])).storedHierarchyData;

                List <string> tables = mm.Stats.Tables;

                // the summary of acessibility/dependency/... is generated at the begining, afterwards it is restroed from the Session
                summary = new DataTable();
                summary.Columns.Add("TableName", typeof(string));
                summary.Columns.Add("Independent", typeof(bool));
                summary.Columns.Add("HasPanels", typeof(bool));
                summary.Columns.Add("Reachable", typeof(bool));

                List <string> unsuitableData = mm.Stats.UnsuitableTables();

                foreach (string tableName in mm.Stats.Tables)
                {
                    if (!mm.Stats.PKs.ContainsKey(tableName))    // exclude the PKLess...
                    {
                        continue;
                    }
                    if (unsuitableData.Contains(tableName))      // ...and the binary
                    {
                        continue;
                    }

                    DataRow r = summary.NewRow();
                    r["TableName"] = tableName;     // get it only once - table is stored in Session and updated

                    // this will take a bit longer as the primary key needs to be determined based on the information schema
                    // A table for which the primary key is at least partly also a foreign key is dependant.
                    r["Independent"] = !(mm.Stats.PKs[tableName].Any(pkCol => mm.Stats.FKs[tableName].Any(fk => fk.myColumn == pkCol)));

                    List <MPanel> tablePanels = (from MPanel p in mm.SysDriver.Panels.Values where p.tableName == tableName select p).ToList <MPanel>();
                    r["HasPanels"] = tablePanels.Count > 0;     // now surely equal to 2 (panels are added/removed in pairs)
                    r["Reachable"] = false;
                    if ((bool)(r["HasPanels"]))
                    {
                        r["Reachable"] = baseNavTable.Select("NavId IN (" + tablePanels[0].panelId + ", " + tablePanels[1].panelId + ")").Length > 0;
                    }
                    summary.Rows.Add(r);
                }

                Session["Summary"] = summary;
            }
            else
            {
                summary = (DataTable)Session["Summary"];
            }



            if (!Page.IsPostBack)
            {
                // the next time grid is set like this will be after panels addition / removal
                TablesGrid.DataSource = summary;
                TablesGrid.DataBind();
                ResetActionClickablility();
            }

            BackButton.PostBackUrl = BackButton.GetRouteUrl("ArchitectShowRoute", new { projectName = _min.Common.Environment.project.Name });
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (EditTablePanel.Visible)
            {
                Table table = new Table();
                try
                {
                    table.NumberOfSeats = Convert.ToInt16(NumberOfSeatsBox.Text);
                    if (table.NumberOfSeats == 0)
                    {
                        throw new ArgumentNullException("Invalid value");
                    }
                }
                catch (Exception error)
                {
                    return;
                }

                table.Description     = DescriptionTextBox.Text;
                table.RestName_Number = old.RestName_Number;
                string json           = JsonConvert.SerializeObject(table);
                var    httpWebRequest = (HttpWebRequest)WebRequest.Create(Properties.Settings.Default.backendHostname + "/Table/Restaurant/edit");

                try
                {
                    httpWebRequest.Headers["Authorization"] = "Basic " + AuthValue;
                    httpWebRequest.Headers["tableNumber"]   = table.RestName_Number.Split(' ')[1];
                    httpWebRequest.ContentType   = "text/json";
                    httpWebRequest.Accept        = "*/*";
                    httpWebRequest.Method        = "POST";
                    httpWebRequest.ContentLength = Encoding.ASCII.GetBytes(json).Length;


                    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                    {
                        streamWriter.Write(json);
                    }
                }
                catch (Exception except)
                {
                    MessageBox.Show("Error occurred");
                }

                try
                {
                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    if (httpResponse.StatusCode.ToString() == "OK")
                    {
                    }
                }
                catch (System.Net.WebException error)
                {
                    MessageBox.Show(error.ToString());
                }

                EditTablePanel.Hide();
                TablesGrid.Show();
                button1.Text = "Choose";
                getJsonMenu();
            }
            else
            {
                DataGridViewRow row   = TablesGrid.CurrentRow;
                Table           table = new Table();
                table.Description     = (string)row.Cells["Description"].Value;
                table.RestName_Number = (string)row.Cells["RestName_Number"].Value;
                table.NumberOfSeats   = (double)row.Cells["NumberOfSeats"].Value;
                old = table;
                EditTablePanel.Show();
                TablesGrid.Hide();
                button1.Text            = "Submit";
                DescriptionTextBox.Text = table.Description;
                NumberOfSeatsBox.Text   = table.NumberOfSeats.ToString();
            }
        }
Beispiel #3
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            mm.SysDriver.FullProjectLoad();
            int    index     = TablesGrid.SelectedIndex;
            string tableName = summary.Rows[index]["TableName"] as string;

            if ((bool)summary.Rows[index]["HasPanels"])     // then remove is the only option that could have been voted for
            {
                IEnumerable <MPanel> toRemove = from MPanel p in mm.SysDriver.Panels.Values where p.tableName == tableName select p;
                foreach (MPanel p in toRemove)
                {
                    mm.SysDriver.RemovePanel(p);
                }
                summary.Rows[index]["HasPanels"] = false;
            }
            else
            {                                                   // otherwise add new editation a navigation panel for this table
                mm.Architect.mappings    = mm.Stats.Mappings[tableName];
                mm.Architect.hierarchies = new List <string>(); // to speed it up, hierarchy nvigation can be set in panel customization
                MPanel editPanel    = mm.Architect.ProposeForTable(tableName);
                MPanel summaryPanel = mm.Architect.proposeSummaryPanel(tableName);


                summaryPanel.SetParentPanel(mm.SysDriver.MainPanel);       // add to db
                editPanel.SetParentPanel(mm.SysDriver.MainPanel);

                foreach (_min.Models.Control c in editPanel.controls)
                {
                    c.targetPanel = summaryPanel;
                }
                foreach (_min.Models.Control c in summaryPanel.controls)
                {
                    c.targetPanel = editPanel;
                }

                summaryPanel.panelName = "Summary of " + tableName;
                editPanel.panelName    = "Editation of " + tableName;
                mm.SysDriver.BeginTransaction();
                mm.SysDriver.AddPanels(new List <_min.Models.Panel> {
                    summaryPanel, editPanel
                });
                mm.SysDriver.CommitTransaction();
                foreach (_min.Models.Control c in summaryPanel.controls)    // simlified for now
                {
                    c.targetPanel = editPanel;
                }
                foreach (_min.Models.Control c in editPanel.controls)
                {
                    c.targetPanel = summaryPanel;
                }

                summary.Rows[index]["HasPanels"] = true;
            }
            // rebuild the grid
            TablesGrid.DataSource = summary;
            TablesGrid.DataBind();
            ResetActionClickablility();
            TablesGrid.SelectedRow.BackColor      = System.Drawing.Color.White;
            TablesGrid.SelectedRowStyle.BackColor = System.Drawing.Color.White;
            TablesGrid.SelectedIndex = -1;
            SaveButton.Enabled       = false;
            mm.SysDriver.IncreaseVersionNumber();

            Session["summary"] = summary;
        }