Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        tmp          = GameObject.Find("TEMP");
        responseCube = GameObject.Find("responseEffect");
        tmp2         = tmp.GetComponent <socketRet>();
        label0       = GameObject.Find("Turret0").GetComponent <TextMesh>();
        label1       = GameObject.Find("Turret1").GetComponent <TextMesh>();
        label2       = GameObject.Find("Turret2").GetComponent <TextMesh>();
        label3       = GameObject.Find("Turret3").GetComponent <TextMesh>();
        label4       = GameObject.Find("Turret4").GetComponent <TextMesh>();
        label5       = GameObject.Find("Turret5").GetComponent <TextMesh>();
        label6       = GameObject.Find("Turret6").GetComponent <TextMesh>();
        label7       = GameObject.Find("Turret7").GetComponent <TextMesh>();
        label8       = GameObject.Find("Turret8").GetComponent <TextMesh>();
        label9       = GameObject.Find("Turret9").GetComponent <TextMesh>();
        label10      = GameObject.Find("Turret10").GetComponent <TextMesh>();

        SocketManager.Socket.On("go", (data) =>
        {
            seqGoJson d = JsonUtility.FromJson <seqGoJson>(data.Json.args[0].ToString());
            // Debug.Log(d.seq);
            tmp2.SocketRetValue = d.seq;
        });
        SocketManager.Socket.On("serverResponse", (data) =>
        {
            Debug.Log("serverResponse " + data.Json.args[0]);
            serverResponse d = JsonUtility.FromJson <serverResponse>(data.Json.args[0].ToString());
            Debug.Log("d.seq " + d.seq + "d.TF " + d.tf);
            tmp2.SocketRetTFseq = d.seq;
            tmp2.SocketRetTF    = d.tf;
        });
        SocketManager.Socket.On("updateScore", (data) =>
        {
            seqScoreJson d = JsonUtility.FromJson <seqScoreJson>(data.Json.args[0].ToString());
            buffer.Add(d.aScore); //갱신된 DB를 주면 됨
            buffer.Add(d.bScore);
            buffer.Add(d.cScore);
            buffer.Add(d.dScore);
            buffer.Add(d.eScore);
            buffer.Add(d.fScore);
            buffer.Add(d.gScore);
            buffer.Add(d.hScore);
            buffer.Add(d.iScore);
            buffer.Add(d.jScore);
            buffer.Add(d.kScore);
        });
    }
Exemplo n.º 2
0
        private void newSummary_Load(object sender, EventArgs e)
        {
            contentsBox.Focus();
            workspaceComboBox.Items.Clear();
            var functions = new codeResources.functions();

            using (codeResources.loadingForm form = new codeResources.loadingForm(APICalls))
            {
                form.ShowDialog();
            }

            if (shouldAbortLoad)
            {
                this.Close();
            }
            else
            {
                try
                {
                    response = JsonConvert.DeserializeObject <serverResponse>(jsonResponse);

                    if (workspaces.contents == null)
                    {
                        storage.currentWorkspaceID = 0;
                        MessageBox.Show(summariesListStrings.NoAvailableWorkspacesLong, summariesListStrings.NoAvailableWorkspaces, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        this.Close();
                    }
                    else
                    {
                        foreach (workspacesContent content in workspaces.contents)
                        {
                            if (content.hours != null)
                            {
                                if (content.read && content.hours.Exists(x => x.classID == storage.classID))
                                {
                                    workspaceComboBox.Items.Add(content.workspaceName);
                                }
                            }
                        }

                        try
                        {
                            if (response.status)
                            {
                                //******* just to reinforce
                                dateBox.CustomFormat = "yyyy-MM-dd";
                                dateBox.Format       = DateTimePickerFormat.Custom;
                                //******* just to reinforce
                                if (summaryNumber != 0)
                                {
                                    isEdit = true;
                                }

                                if (storage.currentWorkspaceID == 0)
                                {
                                    // Workspace not defined yet
                                    workspaceComboBox.SelectedIndex = 0;
                                    storage.currentWorkspaceID      = workspaces.contents[workspaces.contents.FindIndex(z => z.workspaceName == workspaceComboBox.Text)].id;
                                }
                                else
                                {
                                    workspaceComboBox.SelectedItem = workspaces.contents[workspaces.contents.FindIndex(c => c.id == storage.currentWorkspaceID)].workspaceName;
                                }

                                if (isEdit)
                                {
                                    this.Text = newSummaryStrings.EditSummary;
                                    summaryNumberBox.Value = summaryNumber;
                                    dateBox.Value          = DateTime.ParseExact(response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].date, "yyyy-MM-dd", new CultureInfo("pt"));
                                    contentsBox.Text       = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].bodyText;
                                    if (response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].dayHours == 0)
                                    {
                                        missedDayCheckBox.Checked = true;
                                    }
                                    else
                                    {
                                        dayHoursNumberBox.Value = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].dayHours;
                                    }
                                    originalText        = functions.Hash(response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].bodyText);
                                    originalDate        = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].date;
                                    originalWorkspaceID = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].workspaceID;
                                    originalSummaryID   = summaryNumber;
                                    dbRow = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].ID;
                                    if (response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].attachments != null)
                                    {
                                        foreach (var attach in response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].attachments)
                                        {
                                            attachmentsGridView.Rows.Add(attach.filename, newSummaryStrings.RemoveBTN);
                                        }
                                    }
                                }
                                else
                                {
                                    if (response.contents != null)
                                    {
                                        List <Content> workspaceRelated = new List <Content>();
                                        foreach (Content row in response.contents)
                                        {
                                            if (row.workspaceID == storage.currentWorkspaceID)
                                            {
                                                workspaceRelated.Add(row);
                                            }
                                        }

                                        if (workspaceRelated.Count > 0)
                                        {
                                            summaryNumberBox.Value = workspaceRelated[workspaceRelated.Count - 1].summaryNumber + 1;
                                        }
                                        else
                                        {
                                            summaryNumberBox.Value = 1;
                                        }
                                    }
                                    else
                                    {
                                        summaryNumberBox.Value = 1;
                                    }

                                    dateBox.Value = DateTime.ParseExact(DateTime.Today.ToString("yyyy-MM-dd"), "yyyy-MM-dd", new CultureInfo("pt"));
                                }

                                if (!workspaces.contents[workspaces.contents.FindIndex(x => x.id == storage.currentWorkspaceID)].write)
                                {
                                    readOnlyMode = true;
                                    workspaceComboBox.Enabled    = false;
                                    summaryNumberBox.Enabled     = false;
                                    dateBox.Enabled              = false;
                                    contentsBox.ReadOnly         = true;
                                    attachmentsGridView.ReadOnly = true;
                                    addAttachmentBTN.Enabled     = false;
                                    saveBTN.Enabled              = false;
                                }
                            }
                            else
                            {
                                MessageBox.Show(GlobalStrings.Error + ": " + response.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(GlobalStrings.Error + ": " + ex.Message + "\n" + ex.StackTrace + "\n" + jsonResponse, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!functions.CheckForInternetConnection(storage.inUseDomain))
                    {
                        MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(GlobalStrings.Error + ": " + ex.Message + "\n" + jsonWorkspace + "\n" + ex.StackTrace + "\n" + ex.InnerException, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void summariesList_Load(object sender, EventArgs e)
        {
            summarizedHoursHolder.Text = "0"; // must set it to 0 here otherwise, if the workspace is clear, the number of summarized hours will be the last loaded one
            // Requests the Workspace list, showing the loading screen to the user
            using (loadingForm form = new loadingForm(requestWorkpaceList))
            {
                form.ShowDialog();
            }

            if (shouldAbort)
            {
                this.Close();
            }
            else
            {
                try
                {
                    workspaceResponse = JsonConvert.DeserializeObject <workspacesServerResponse>(jsonResponse);
                    if (workspaceResponse.status)
                    {
                        if (workspaceResponse.contents == null || !workspaceResponse.contents.Exists(x => x.hours.Exists(y => y.classID == storage.classID)))
                        {
                            storage.currentWorkspaceID = 0;
                            MessageBox.Show(summariesListStrings.NoAvailableWorkspacesLong, summariesListStrings.NoAvailableWorkspaces, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            this.Close();
                        }
                        else
                        {
                            workspaceComboBox.Items.Clear();
                            foreach (workspacesContent row in workspaceResponse.contents)
                            {
                                if (row.hours != null)
                                {
                                    if (row.read && row.hours.Exists(x => x.classID == storage.classID))
                                    {
                                        workspaceComboBox.Items.Add(row.workspaceName);
                                    }
                                }
                            }

                            if (workspaceComboBox.Items.Count == 0)
                            {
                                // If there are no workspaces with read permission, show warning to user and close dialog
                                storage.currentWorkspaceID = 0;
                                MessageBox.Show(summariesListStrings.NoAvailableWorkspacesLong, summariesListStrings.NoAvailableWorkspaces, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                this.Close();
                            }
                            else
                            {
                                int totalWorkspaceHours = 0;

                                if (workspaceName == null || workspaceName == string.Empty || workspaceName == "")
                                {
                                    int index = workspaceResponse.contents.FindIndex(x => x.read == true && x.hours.Exists(c => c.classID == storage.classID));
                                    workspaceSelectedID            = workspaceResponse.contents[index].id;
                                    workspaceName                  = workspaceResponse.contents[index].workspaceName;
                                    workspaceComboBox.SelectedItem = workspaceName;
                                    totalWorkspaceHours            = workspaceResponse.contents[index].hours[workspaceResponse.contents[index].hours.FindIndex(x => x.classID == storage.classID)].totalHours;
                                    totalHoursHolder.Text          = totalWorkspaceHours.ToString();
                                }
                                else
                                {
                                    int workspaceIndex = workspaceResponse.contents.FindIndex(x => x.workspaceName == workspaceName);
                                    workspaceSelectedID            = workspaceResponse.contents[workspaceIndex].id;
                                    totalWorkspaceHours            = workspaceResponse.contents[workspaceIndex].hours[workspaceResponse.contents[workspaceIndex].hours.FindIndex(x => x.classID == storage.classID)].totalHours;
                                    totalHoursHolder.Text          = totalWorkspaceHours.ToString();
                                    workspaceComboBox.SelectedItem = workspaceName;
                                }

                                storage.currentWorkspaceID = workspaceSelectedID;

                                try
                                {
                                    using (loadingForm form = new loadingForm(requestSummaryList))
                                    {
                                        form.ShowDialog();
                                    }

                                    response = JsonConvert.DeserializeObject <serverResponse>(jsonResponse);

                                    if (response.status)
                                    {
                                        int summarizedHours = 0;
                                        dataGrid.Rows.Clear();
                                        dataGrid.Refresh();
                                        if (response.contents != null)
                                        {
                                            dataGrid.ColumnCount             = 3;
                                            dataGrid.Columns[0].Name         = "date";
                                            dataGrid.Columns[0].HeaderText   = summariesListStrings.Date;
                                            dataGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                                            dataGrid.Columns[1].Name         = "summaryNumber";
                                            dataGrid.Columns[1].HeaderText   = "#";
                                            dataGrid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                                            dataGrid.Columns[2].Name         = "contents";
                                            dataGrid.Columns[2].HeaderText   = summariesListStrings.Summary;
                                            dataGrid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                                            dataGrid.AllowUserToDeleteRows   = false;
                                            dataGrid.AllowUserToAddRows      = false;
                                            dataGrid.MultiSelect             = false; //just to reinforce

                                            var rows = new List <string[]>();
                                            foreach (Content content in response.contents)
                                            {
                                                string[] row1 = new string[] { content.date.ToString(), content.summaryNumber.ToString(), content.bodyText.ToString() };
                                                summarizedHours += content.dayHours;
                                                rows.Add(row1);
                                            }

                                            foreach (string[] rowArray in rows)
                                            {
                                                dataGrid.Rows.Add(rowArray);
                                            }
                                            dataGrid.Sort(this.dataGrid.Columns[0], Properties.Settings.Default.summaryOrderDate);
                                            double daysLeft = 0;
                                            daysLeft = (totalWorkspaceHours - summarizedHours) / 7;
                                            summarizedHoursHolder.Text = summarizedHours.ToString();
                                            hoursRemainingHolder.Text  = (totalWorkspaceHours - summarizedHours).ToString() + " " + String.Format(GlobalStrings.DaysRemaining, Math.Round(daysLeft));
                                        }
                                        else
                                        {
                                            hoursRemainingHolder.Text = totalWorkspaceHours.ToString() + " " + String.Format(GlobalStrings.DaysRemaining, Math.Round((double)totalWorkspaceHours / 7));
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show(GlobalStrings.Error + ": " + response.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    functions functions = new functions();
                                    if (!functions.CheckForInternetConnection(storage.inUseDomain))
                                    {
                                        MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                    else
                                    {
                                        MessageBox.Show(GlobalStrings.CriticalError + ": " + ex.Message + "\n" + jsonResponse + "\n" + ex.StackTrace, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(GlobalStrings.Error + ": " + workspaceResponse.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    functions functions = new functions();
                    if (!functions.CheckForInternetConnection(storage.inUseDomain))
                    {
                        MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(GlobalStrings.Error + ": " + ex.Message + "\n" + jsonResponse + "\n" + ex.StackTrace, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }