Matrix Row Editable
Thomas H.
Hallo,ich habe ein Problem beim zurückschreiben von Werten in eine Matrix.
In meiner Customizer Regel, soll er Werte in eine Matrix zurückschreiben ( Zeile für Zeile)
Leider bekomme ich eine Fehlermeldung, wenn eine Zeile ( eine Position schon abgeschlossen ist).
Da ich hier nicht reinschreiben kann. Wie kann ich vorher überprüfen ob diese Zeile schon geschlossen ist oder nicht.
Gruß
Thomas
Sebastian Schweer
Hallo Thomas,soweit ich weiß ist es nicht möglich, direkt zu prüfen ob eine Matrix Row editierbar ist oder nicht.
Ich selbst habe das Problem auch und dann diverse Abfragen selbstprogrammiert um zu prüfen ob die Zeile Editierbar ist.
z.B. Ist ein Vendor/Customer Code (Feld 4) eingetragen. Falls nein, ist die Matrix nicht editierbar.
Handelt es sich um eine Summen Zeile oder Textzeile usw.
Hier ist noch ein Codebeispiel das ich in meiner DLL habe. Das ist allerdings auf meine Bedürfnisse zugeschnitten:
// select the Matrix-Grid from the Mask
Matrix matrix = Matrix.GetFromUID(pVal.Form, "38");
// get the current selected Row of the Matrix
int currentRow = pVal.Row - 1;
// Type of Row
string type = matrix.GetValue("257", currentRow);
// check if current Row is an item Row and not a Text Row or a Sum Row
if(type != "T" && type != "S")
{
// get the ItemCode from the current Row and set as global
Beumer.IT.B1.PriceListConcept.globalItemCode = matrix.GetValue("1", currentRow).ToString() ;
}
/// <summary>
/// Checks if acces to a Matrix can be granted or not
/// This Check is nessessary to avoid to write to a closed Matrix Row, which causes an exception
/// Acces to Matrix will only be granted, if the Document is in the Add Mode, or is a Sales Order, Sales Quotation, Purchase Order or Purchase Quotation and if now rows are closed
/// </summary>
/// <param name="form">the form which is to check and which contains the document</param>
/// <returns>ture if access is granted, false is access is not granted</returns>
public static bool CheckMatrixAccess(SwissAddonFramework.UI.Components.Form form)
{
WriteStatusBarComment("PLC.dll CheckMatrixAccess(): In Matrix Access");
try
{
// if Business Partner is not filled out, Matrix can not be accessed
if((string.IsNullOrEmpty(TextEdit.GetFromUID(form, "4").Value.ToString())))
{
return false;
}
WriteStatusBarComment("PLC.dll CheckMatrixAccess(): Business Parter is filled out: ");
string formMode = form.Mode.ToString();
// Matrix can be changed if the Document is in the Add Mode and Business Partner is entered in the Field in the left upper corner
if (formMode == "ADD")
{
WriteStatusBarComment("PLC.dll CheckMatrixAccess(): Form in Add Mode: " + formMode);
return true;
}
else
{
// if the document is not in the Update Mode it is only allowed on Sales Orders/Sales Quotations / Purchase Orders and Purcahse Quotations to change something,
// and in that case only than if no row is closed
// check if table is one of the 4 allowed forms
// get the table of the Form
int tableNumber = int.Parse(SwissAddonFramework.UI.Components.TextEdit.GetFromUID(form, "4").Form.Type.ToString());
string tableName = getTableName(tableNumber);
WriteStatusBarComment("TableName: " + tableName);
// get the Code of the Business Partner
string bpName = SwissAddonFramework.UI.Components.TextEdit.GetFromUID(form, "4").Value.ToString();
// if table is not one of the 4 tables return false and get out of the Method
if (tableName == "ORDR" || tableName == "OQUT" || tableName == "OPOR" || tableName == "OPQT")
{
// Now only entrence to the tables is allowed, if a document is in the Add Mode or one of the four tables SO, SQ, PO, PQ
// Now we have also to check if one of the Rows is already closed
// if a row is closed, changes are not allowed
// get the Number of the Document
string docNum = SwissAddonFramework.UI.Components.TextEdit.GetFromUID((SwissAddonFramework.UI.Components.Form)form, "8").Value.ToString();
// get the table of ) the Form
bool isNotCanceled = true;
System.Data.SqlClient.SqlCommand cmdCMA = new System.Data.SqlClient.SqlCommand();
cmdCMA.CommandText = "select LineStatus from " + tableName.Substring(1, 3) + "1 where docentry in (select docentry from " + tableName + " where docnum = " + docNum + " and CardCode = '" + bpName + "')";
WriteStatusBarComment("cmdCMA: " + cmdCMA.CommandText);
using (System.Data.SqlClient.SqlDataReader sdrCMA = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQuery(cmdCMA))
{
while (sdrCMA.Read())
{
string temp = sdrCMA.GetValue(0).ToString();
WriteStatusBarComment("LineStatus: " + temp);
if (temp == "C")
{
isNotCanceled = false;
}
}
sdrCMA.Close();
}
return isNotCanceled;
}
else
{
return false;
}
}
}
catch (Exception ex)
{
SwissAddonFramework.Messaging.StatusBar.WriteError("Error: " + ex.Message);
SwissAddonFramework.Messaging.StatusBar.WriteError("Error in UpdateMatrixRows: " + ex.StackTrace);
return false;
}
}
Best Regards,
Sebastian
0
Please sign in to leave a comment.
Comments
0 comments