EBDN - Community - Question & Answers

  Sunday, 22 August 2021
  3 Replies
  1.2K Visits
0
Votes
Undo
hello everyone
I have the following problems when creating a new sub object.
The code is as follows:
//Throw exception location
ObjectItem newchild = Catelog.NewChild((ObjectKind)long.Parse(oKind), (ObjectType)long.Parse(oType));

private void buttonDownload_Click(object sender, EventArgs e)
{
try
{
if (dataGridView1.Rows.Count != 0)
{
List<NewObject> newObjects = new List<NewObject>();
string oKind=((ItemObject)KindCombox.SelectedItem).Value;
// ObjectKind oKind = ObjectKind(ItemObject)KindCombox.SelectedItem).Value;
//long oType = long.Parse(((ItemObject)TypeCombox.SelectedItem).Value.Replace("_sub", ""));
string oType=((ItemObject)TypeCombox.SelectedItem).Value.Replace("_sub", "");
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[0].Value.ToString() == "True")
{
NewObject obj = (NewObject)row.Tag;
newObjects.Add(obj);
}
}
using (WaitDialog dlg = m_myApplication.Dialogs.CreateWaitDialog())
{
int ss = 1;
dlg.ShowDialogAsync(newObjects.Count + 1, "开始下载");
dlg.UpdateDialog(ss, "预计需要" + newObjects.Count + "秒,请稍等。。");
foreach (NewObject obj in newObjects)
{
List<ObjectItem> objs = Catelog.Children.Where(p => p.Kind == ((ObjectKind)long.Parse(oKind)) && p.TypeId == (ObjectType)long.Parse(oType)).ToList();
List<ObjectItem> item = objs.Where(p => p.Attributes.FindById((AttributeId)Confignation.ObjID).Value != null && p.Attributes.FindById((AttributeId)Confignation.ObjID).Value.ToString() == obj.Id).ToList();
if (item.Count != 0)
{
Comm.AttValueUpdate(item[0], obj);
}
else
{
ObjectItem newchild = Catelog.NewChild((ObjectKind)long.Parse(oKind), (ObjectType)long.Parse(oType));
Comm.AttValueUpdate(newchild, obj);
}
dlg.UpdateDialog(ss + 1);
}
dlg.CloseDialog();
MessageBox.Show("下载完成");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}