Добрый день!
Необходимо создать WinForm в виде динамической матрицы, которая бы встраивалась в Navision как кастомный компонент - Add-In.
В настоящий момент создал динамическую двумерную матрицу, которая инициализируеться данными из Navision.
В качестве источника данных использую веб-сервис OData.
В данный момент есть проблемы:
1) Как открыть сущность Navision из WinFrom, вернее какой метод для этого существует и как его повесить как событие на кнопки в WinFrom;
2) Каким образом создать DLL сборку WinFrom Add-in для Navision 2013 R2
Вот пример кода
Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAVMatrix.ServiceReference1;
namespace NAVMatrix
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static List<NAVMatrix.ServiceReference1.Matrix_list> PrintCustomersCalledCust(NAV nav)
{
var Matrix = from c in nav.Matrix_list
select c;
List<NAVMatrix.ServiceReference1.Matrix_list> Matrix1 = Matrix.ToList();
return Matrix1;
}
private void Form1_Load(object sender, EventArgs e)
{
//Коннектимся к веб-сервису OData
NAV nav = new NAV(new Uri("http://raptor:7048/DynamicsNAV71/OData/Company('DREVO')"));
nav.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
List<NAVMatrix.ServiceReference1.Matrix_list> Matrix = PrintCustomersCalledCust(nav);
int L = Matrix.Count;
this.tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.ColumnStyles.Clear();
this.tableLayoutPanel1.RowStyles.Clear();
tableLayoutPanel1.ColumnCount = Matrix[L - 1].X + 1;
tableLayoutPanel1.RowCount = Matrix[L - 1].Y + 1;
this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None;
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left;
for (int i = 0; i < L; i++)
{
for (int x = Matrix[i].X; x < (Matrix[i].X + 1); x++)
{
this.tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
for (int y = Matrix[i].Y; y < (Matrix[i].Y + 1); y++)
{
if (x == 0)
{
this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
Button cmd = new Button();
if (i%2 == 1)
cmd.BackColor = System.Drawing.SystemColors.HotTrack;
else {
cmd.BackColor = System.Drawing.Color.Yellow;}
cmd.Size = new System.Drawing.Size(105, 41);
cmd.Text = string.Format("({0}, {1}, {2}, {3}, {4}, {5})", Matrix[i].X, Matrix[i].Y, Matrix[i].Val1, Matrix[i].Val2, Matrix[i].Val3, Matrix[i].Val4);
this.tableLayoutPanel1.Controls.Add(cmd, x, y);
}
}
}
}
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 47);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(768, 194);
this.tableLayoutPanel1.TabIndex = 0;
this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(780, 414);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
}
}
Вот как выглядит матрица
Код для Add-In должен быть приблизительно таким?
Код:
using System.Windows.Forms;
using Microsoft.Dynamics.Framework.UI.Extensibility;
using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
namespace AddInSamples
{
[ControlAddInExport("SampleControl1_MyDymanicMatrix")]
public class MyDymanicMatrixControlAddIn : WinFormsControlAddInBase
{
protected override System.Windows.Forms.Control CreateControl()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 47);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(768, 194);
this.tableLayoutPanel1.TabIndex = 0;
this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(780, 414);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
private void Form1_Load(object sender, EventArgs e)
{
//Коннектимся к веб-сервису OData
NAV nav = new NAV(new Uri("http://raptor:7048/DynamicsNAV71/OData/Company('DREVO')"));
nav.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
List<NAVMatrix.ServiceReference1.Matrix_list> Matrix = PrintCustomersCalledCust(nav);
int L = Matrix.Count;
this.tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.ColumnStyles.Clear();
this.tableLayoutPanel1.RowStyles.Clear();
tableLayoutPanel1.ColumnCount = Matrix[L - 1].X + 1;
tableLayoutPanel1.RowCount = Matrix[L - 1].Y + 1;
this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None;
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left;
for (int i = 0; i < L; i++)
{
for (int x = Matrix[i].X; x < (Matrix[i].X + 1); x++)
{
this.tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
for (int y = Matrix[i].Y; y < (Matrix[i].Y + 1); y++)
{
if (x == 0)
{
this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
Button cmd = new Button();
if (i%2 == 1)
cmd.BackColor = System.Drawing.SystemColors.HotTrack;
else {
cmd.BackColor = System.Drawing.Color.Yellow;}
cmd.Size = new System.Drawing.Size(105, 41);
cmd.Text = string.Format("({0}, {1}, {2}, {3}, {4}, {5})", Matrix[i].X, Matrix[i].Y, Matrix[i].Val1, Matrix[i].Val2, Matrix[i].Val3, Matrix[i].Val4);
this.tableLayoutPanel1.Controls.Add(cmd, x, y);
}
}
}
}
private List<NAVMatrix.ServiceReference1.Matrix_list> PrintCustomersCalledCust(NAV nav)
{
var Matrix = from c in nav.Matrix_list
select c;
List<NAVMatrix.ServiceReference1.Matrix_list> Matrix1 = Matrix.ToList();
return Matrix1;
}
}
}