コード例 #1
0
ファイル: DlgEditJob.cs プロジェクト: perforce/P4VS
        public static P4.Job Show(P4ScmProvider Scm, P4.Job job)
        {
            if (Scm != null)
            {
                scm = Scm;
            }
            if (job == null)
            {
                return(null);
            }
            if (dlgRetry == false)
            {
                attachedFixes = new List <Changelist>();
            }
            dlgRetry   = false;
            currentJob = job;

            P4.Options opts = new P4.Options();
            opts["-o"] = null;
            jobspec    = Scm.Connection.Repository.GetFormSpec(opts, "job");

            DlgEditJob dlg = new DlgEditJob();

            if (dlg.DialogResult == DialogResult.Cancel)
            {
                return(null);
            }

            string jobName = job.Id;

            if (job.Id == "new")
            {
                jobName = "New";
            }
            dlg.Text = dlg.Text + " " + jobName + " (" +
                       Scm.Connection.Repository.Server.Address.ToString() + ", " +
                       Scm.Connection.User + ")";

            dlg.addBtn.Enabled  = false;
            dlg.messageLbl.Text = "";

            P4.Job jobInfo = job;

            Dictionary <string, string> fields   = jobspec.FieldMap;
            Dictionary <string, string> valueMap = jobspec.Values;

            //string[] fields = Regex.Split(spec, ";;");

            int singleline = 0;

            // determine how many single line fields
            // exist in the job
            foreach (P4.SpecField field in jobspec.Fields)
            {
                if (field.DataType == SpecFieldDataType.Bulk ||
                    field.DataType == SpecFieldDataType.Text)
                {
                    continue;
                }
                singleline++;
            }

            int leftCol            = (singleline + 1) / 2;
            int leftcount          = 0; //job is there
            int rightcount         = 0;
            int bottomcount        = 0;
            int idx                = 0;
            int lidx               = 0; // Job: is 0
            int ridx               = 0;
            int bidx               = 0;
            int longestLeftLabel   = 0;
            int longestRightLabel  = 0;
            int longestBottomLabel = 0;

            Label[]       leftLabels       = new Label[jobspec.Fields.Count];
            TextBox[]     leftTextboxes    = new TextBox[jobspec.Fields.Count];
            ComboBox[]    leftComboboxes   = new ComboBox[jobspec.Fields.Count];
            Label[]       rightLabels      = new Label[jobspec.Fields.Count];
            TextBox[]     rightTextboxes   = new TextBox[jobspec.Fields.Count];
            ComboBox[]    rightComboboxes  = new ComboBox[jobspec.Fields.Count];
            Label[]       bottomLabels     = new Label[jobspec.Fields.Count];
            RichTextBox[] bottomTextboxes  = new RichTextBox[jobspec.Fields.Count];
            ComboBox[]    bottomComboboxes = new ComboBox[jobspec.Fields.Count];


            foreach (P4.SpecField field in jobspec.Fields)
            {
                string fieldname = field.Name;
                if (field.DataType == SpecFieldDataType.Bulk ||
                    field.DataType == SpecFieldDataType.Text)
                {
                    bottomLabels[bidx]          = new Label();
                    bottomLabels[bidx].AutoSize = true;

                    // set name and location for large text box labels
                    bottomLabels[bidx].Text = fieldname + ":";
                    Point location = dlg.jobLbl.Location;
                    location.Y = location.Y + (25 * leftCol) + (125 * bottomcount);
                    bottomLabels[bidx].Location = location;
                    bottomLabels[bidx].Name     = fieldname + "Lbl";
                    bottomLabels[bidx].Width    = bottomLabels[bidx].PreferredWidth;

                    // determine size of label and check to determine if
                    // the current label is the widest

                    if (bottomLabels[bidx] != null && bottomLabels[longestBottomLabel] != null)
                    {
                        if (bidx > 0 && bottomLabels[bidx].Width > bottomLabels[longestBottomLabel].Width)
                        {
                            longestBottomLabel = bidx;
                        }
                    }

                    // anchoring
                    bottomLabels[bidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;

                    bottomTextboxes[bidx]                  = new RichTextBox();
                    location.X                            += (bottomLabels[bidx].Width + 5);
                    bottomTextboxes[bidx].Name             = fieldname + "TB";
                    bottomTextboxes[bidx].Location         = location;
                    bottomTextboxes[bidx].Height           = 120;
                    bottomTextboxes[bidx].Width            = 350;
                    bottomTextboxes[bidx].Multiline        = true;
                    bottomTextboxes[bidx].ScrollBars       = RichTextBoxScrollBars.Vertical;
                    bottomTextboxes[bidx].WordWrap         = true;
                    bottomTextboxes[bidx].ShortcutsEnabled = true;
                    if (job.ContainsKey(field.Name))
                    {
                        if (job[field.Name].ToString() == "<enter description here>\n")
                        {
                            bottomTextboxes[bidx].Text = job[field.Name].ToString();
                        }
                        else
                        {
                            bottomTextboxes[bidx].Text = job[field.Name].ToString().Replace("\n", "\r\n");
                        }
                    }

                    // anchoring
                    bottomTextboxes[bidx].Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;

                    bottomcount++;
                    bidx++;
                }

                else
                {
                    Point location = new Point();


                    if (leftcount < leftCol)
                    {
                        leftLabels[lidx]      = new Label();
                        leftLabels[lidx].Text = fieldname + ":";
                        location    = dlg.jobLbl.Location;
                        location.Y += (25 * leftcount);

                        // anchoring
                        leftLabels[lidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;

                        leftLabels[lidx].Location = location;
                        leftLabels[lidx].Name     = fieldname + "Lbl";
                        leftLabels[lidx].Width    = leftLabels[lidx].PreferredWidth;

                        // determine size of label and check to determine if
                        // the current label is the widest

                        if (leftLabels[lidx] != null && leftLabels[longestLeftLabel] != null)
                        {
                            if (lidx > 0 && leftLabels[lidx].Width > leftLabels[longestLeftLabel].Width)
                            {
                                longestLeftLabel = lidx;
                            }
                        }
                    }
                    else
                    {
                        rightLabels[ridx] = new Label();
                        //string fieldname = field.Name;
                        rightLabels[ridx].Text = fieldname + ":";
                        location    = dlg.jobLbl.Location;
                        location.Y += (25 * rightcount);
                        //int indent = (dlg.jobLbl.Width + 160);
                        //location.X = location.X + indent;

                        location.X = dlg.splitContainer.Panel1.Width / 2;


                        // anchoring
                        rightLabels[ridx].Anchor = AnchorStyles.Top | AnchorStyles.Left;

                        rightLabels[ridx].Location = location;
                        rightLabels[ridx].Name     = fieldname + "Lbl";
                        rightLabels[ridx].Width    = rightLabels[ridx].PreferredWidth;

                        // determine size of label and check to determine if
                        // the current label is the widest

                        if (rightLabels[ridx] != null && rightLabels[longestRightLabel] != null)
                        {
                            if (ridx > 0 && rightLabels[ridx].Width > rightLabels[longestRightLabel].Width)
                            {
                                longestRightLabel = ridx;
                            }
                        }
                    }



                    if (field.DataType == SpecFieldDataType.Select)
                    {
                        // anchoring
                        if (leftcount < leftCol)
                        {
                            leftComboboxes[lidx] = new ComboBox();
                            leftComboboxes[lidx].DropDownStyle = ComboBoxStyle.DropDownList;
                            leftComboboxes[lidx].Width         = 100;
                            leftComboboxes[lidx].Height        = 20;
                            int tab = leftLabels[lidx].Width + 5;
                            location.X = leftLabels[lidx].Location.X + tab;
                            leftComboboxes[lidx].Name     = fieldname + "TB";
                            leftComboboxes[lidx].Location = location;
                            string   values = valueMap[field.Name];
                            string[] val    = values.Split('/');
                            leftComboboxes[lidx].Items.AddRange(val);
                            if (job.ContainsKey(fieldname))
                            {
                                object sel = null;
                                job.TryGetValue(fieldname, out sel);
                                string selected = sel.ToString();
                                if (selected != null && selected != "\"\"")
                                {
                                    leftComboboxes[lidx].SelectedItem = selected;
                                }
                                else
                                {
                                    leftComboboxes[lidx].SelectedItem = val[0];
                                }
                            }
                            leftComboboxes[lidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;
                            lidx++;
                            leftcount++;
                        }
                        else
                        {
                            rightComboboxes[ridx] = new ComboBox();
                            rightComboboxes[ridx].DropDownStyle = ComboBoxStyle.DropDownList;
                            rightComboboxes[ridx].Width         = 100;
                            rightComboboxes[ridx].Height        = 20;
                            int tab = rightLabels[ridx].Width + 5;
                            location.X = rightLabels[ridx].Location.X + tab;
                            rightComboboxes[ridx].Name     = fieldname + "TB";
                            rightComboboxes[ridx].Location = location;
                            string   values = valueMap[field.Name];
                            string[] val    = values.Split('/');
                            rightComboboxes[ridx].Items.AddRange(val);
                            if (job.ContainsKey(fieldname))
                            {
                                object sel = null;
                                job.TryGetValue(fieldname, out sel);
                                string selected = sel.ToString();
                                if (selected != null && selected != "\"\"")
                                {
                                    rightComboboxes[ridx].SelectedItem = selected;
                                }
                                else
                                {
                                    rightComboboxes[ridx].SelectedItem = val[0];
                                }
                            }
                            rightComboboxes[ridx].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                            ridx++;
                            rightcount++;
                        }
                    }

                    else
                    {
                        // anchoring
                        if (leftcount < leftCol)
                        {
                            leftTextboxes[lidx] = new TextBox();

                            //leftTextboxes[lidx].AutoSize = true;
                            int tab = leftLabels[lidx].Width + 5;
                            location.X = leftLabels[lidx].Location.X + tab;
                            leftTextboxes[lidx].Name             = fieldname + "TB";
                            leftTextboxes[lidx].Location         = location;
                            leftTextboxes[lidx].Height           = 15;
                            leftTextboxes[lidx].Width            = 100;
                            leftTextboxes[lidx].ShortcutsEnabled = true;
                            if (field.FieldType == SpecFieldFieldType.Always ||
                                field.FieldType == SpecFieldFieldType.Once ||
                                field.Code == 101)
                            {
                                leftTextboxes[lidx].ReadOnly = true;
                            }
                            if (job.ContainsKey(field.Name))
                            {
                                if ((field.DataType == P4.SpecFieldDataType.Date) &&
                                    p4Date() == false)
                                {
                                    DateTime d;
                                    DateTime.TryParse(job[field.Name].ToString(), out d);
                                    leftTextboxes[lidx].Text = d.ToString("MM/d/yyyy h:mm:ss tt");
                                }
                                else
                                {
                                    leftTextboxes[lidx].Text = job[field.Name].ToString();
                                }
                            }
                            leftTextboxes[lidx].Anchor = AnchorStyles.Left | AnchorStyles.Top;
                            lidx++;
                            leftcount++;
                        }
                        else
                        {
                            rightTextboxes[ridx] = new TextBox();
                            int tab = rightLabels[ridx].Width + 8;
                            location.X = rightLabels[ridx].Location.X + tab;
                            rightTextboxes[ridx].Name             = fieldname + "TB";
                            rightTextboxes[ridx].Location         = location;
                            rightTextboxes[ridx].Height           = 15;
                            rightTextboxes[ridx].Width            = 100;
                            rightTextboxes[ridx].ShortcutsEnabled = true;
                            if (field.FieldType == SpecFieldFieldType.Always ||
                                field.FieldType == SpecFieldFieldType.Once ||
                                field.Code == 101)
                            {
                                rightTextboxes[ridx].ReadOnly = true;
                            }
                            if (job.ContainsKey(field.Name))
                            {
                                if ((field.DataType == P4.SpecFieldDataType.Date) &&
                                    p4Date() == false)
                                {
                                    DateTime d;
                                    DateTime.TryParse(job[field.Name].ToString(), out d);
                                    rightTextboxes[ridx].Text = d.ToString("MM/d/yyyy h:mm:ss tt");
                                }
                                else
                                {
                                    rightTextboxes[ridx].Text = job[field.Name].ToString();
                                }
                            }
                            rightTextboxes[ridx].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                            ridx++;
                            rightcount++;
                        }
                    }
                }
            }

            // adjust all the placements based on largest label size
            // and dialog real estate remaining

            int fieldX     = 0;
            int fieldWidth = 0;

            // bottom labels and textboxes


            if (leftLabels[longestLeftLabel].Width >= bottomLabels[longestBottomLabel].Width)
            {
                fieldX = leftLabels[longestLeftLabel].Width + 5 +
                         leftLabels[longestLeftLabel].Location.X;
                fieldWidth = dlg.splitContainer.Panel1.Width - (fieldX + 10);
            }
            else
            {
                fieldX = bottomLabels[longestBottomLabel].Width + 5 +
                         leftLabels[longestBottomLabel].Location.X;
                fieldWidth = dlg.splitContainer.Panel1.Width - (fieldX + 10);
            }
            foreach (RichTextBox bottomTextbox in bottomTextboxes)
            {
                if (bottomTextbox != null)
                {
                    bottomTextbox.SetBounds(fieldX, bottomTextbox.Location.Y,
                                            fieldWidth, bottomTextbox.Size.Height);
                }
            }


            // left labels and textboxes / comboboxes
            if (leftLabels[longestLeftLabel].Width >= bottomLabels[longestBottomLabel].Width)
            {
                fieldX = leftLabels[longestLeftLabel].Width + 5 +
                         leftLabels[longestLeftLabel].Location.X;
                fieldWidth = (dlg.splitContainer.Panel1.Width / 2) - fieldX;
            }
            else
            {
                fieldX = bottomLabels[longestBottomLabel].Width + 5 +
                         leftLabels[longestBottomLabel].Location.X;
                fieldWidth = (dlg.splitContainer.Panel1.Width / 2) - fieldX;
            }
            foreach (ComboBox leftCombobox in leftComboboxes)
            {
                if (leftCombobox != null)
                {
                    leftCombobox.SetBounds(fieldX, leftCombobox.Location.Y,
                                           fieldWidth, leftCombobox.Size.Height);
                }
            }
            foreach (TextBox leftTextbox in leftTextboxes)
            {
                if (leftTextbox != null)
                {
                    leftTextbox.SetBounds(fieldX, leftTextbox.Location.Y,
                                          fieldWidth, leftTextbox.Size.Height);
                }
            }

            // right labels and textboxes / comboboxes
            fieldX = dlg.splitContainer.Panel1.Width / 2 + 5 +
                     rightLabels[longestRightLabel].Width;
            fieldWidth = (dlg.splitContainer.Panel1.Width / 2) -
                         (rightLabels[longestRightLabel].Width + 10);
            foreach (ComboBox rightCombobox in rightComboboxes)
            {
                if (rightCombobox != null)
                {
                    rightCombobox.SetBounds(fieldX, rightCombobox.Location.Y,
                                            fieldWidth, rightCombobox.Size.Height);
                }
            }
            foreach (TextBox rightTextbox in rightTextboxes)
            {
                if (rightTextbox != null)
                {
                    rightTextbox.SetBounds(fieldX, rightTextbox.Location.Y,
                                           fieldWidth, rightTextbox.Size.Height);
                }
            }


            dlg.splitContainer.Panel1.Controls.AddRange(leftLabels);
            dlg.splitContainer.Panel1.Controls.AddRange(leftTextboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(leftComboboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(rightLabels);
            dlg.splitContainer.Panel1.Controls.AddRange(rightTextboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(rightComboboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(bottomLabels);
            dlg.splitContainer.Panel1.Controls.AddRange(bottomTextboxes);
            dlg.splitContainer.Panel1.Controls.AddRange(bottomComboboxes);

            dlg.splitContainer.Panel1.Refresh();

            // add fixes here
            Options     fixOpts = new Options(GetFixesCmdFlags.IncludeIntegrations, -1, job.Id, -1);
            IList <Fix> fixes   = Scm.Connection.Repository.GetFixes(null, fixOpts);

            if (fixes != null)
            {
                foreach (Fix fix in fixes)
                {
                    Changelist change = Scm.GetChangelist(fix.ChangeId);

                    if (change != null)
                    {
                        dlg.addChangeToFixesLV(change);
                        attachedFixes.Add(change);
                    }
                }
            }

            if (attachedFixes.Count > 0)
            {
                foreach (Changelist fix in attachedFixes)
                {
                    if (fix != null)
                    {
                        dlg.addChangeToFixesLV(fix);
                    }
                }
            }


            if (dlg.ShowDialog() != DialogResult.Cancel)
            {
                idx = 0;
                if (dlg.DialogResult == DialogResult.OK)
                {
                    foreach (P4.SpecField field in jobspec.Fields)
                    {
                        string fieldname = field.Name;

                        Control[] control = dlg.splitContainer.Panel1.Controls.Find(fieldname + "TB", false);
                        if (control != null && control.Length > 0 && control[0] != null)
                        {
                            if ((field.DataType == SpecFieldDataType.Bulk ||
                                 field.DataType == SpecFieldDataType.Text) &&
                                control[0].Text != "<enter description here>\n")
                            {
                                job.IsFieldMultiLine[fieldname] = true;
                            }
                            if (field.DataType == SpecFieldDataType.Date)
                            {
                                job[fieldname] = "";
                            }
                            else
                            {
                                job[fieldname] = control[0].Text;
                            }
                        }
                        idx++;
                    }

                    P4.Job savedJob = scm.saveJob(job);
                    if (savedJob == null)
                    {
                        dlgRetry = true;
                        //dlg.Show();
                        Show(Scm, job);
                        return(job);
                    }
                    if (dlg.SelectedChangelistList != null)
                    {
                        foreach (P4.Changelist change in dlg.SelectedChangelistList)
                        {
                            try
                            {
                                opts = new P4.Options(P4.FixJobsCmdFlags.None, -1, null);
                                IList <P4.Fix> fixToAttach = change.FixJobs(opts, savedJob);
                            }
                            catch (Exception ex)
                            {
                                Scm.ShowException(ex);
                            }
                        }
                    }

                    if (dlg.UnselectedChangelistList != null)
                    {
                        foreach (P4.Changelist change in dlg.UnselectedChangelistList)
                        {
                            if (change != null && (change.Jobs != null && change.Jobs.ContainsKey(currentJob.Id)))
                            {
                                try
                                {
                                    opts = new P4.Options(P4.FixJobsCmdFlags.Delete, -1, null);
                                    IList <P4.Fix> fixToRemove = change.FixJobs(opts, savedJob);
                                }
                                catch (Exception ex)
                                {
                                    Scm.ShowException(ex);
                                }
                            }
                        }
                    }

                    return(savedJob);
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: DlgEditJob.cs プロジェクト: perforce/P4VS
 public static P4.Job EditJob(P4ScmProvider Scm, P4.Job job)
 {
     P4.Job editedjob = DlgEditJob.Show(Scm, job);
     return(editedjob);
 }