public Result Create(ItemType ObjItemType) { try { if (service == null) { LogError.log.Error("Service is null"); throw new Exception("Service is null"); } Entity objEntity = new Entity("ivg_itemtype"); objEntity.Attributes["ivg_id"] = ObjItemType.Ivg_id; objEntity.Attributes["ivg_name"] = ObjItemType.Ivg_name; CheckDuplicate objcheck = new CheckDuplicate(); string[] columName = { "ivg_id" }; string[] att = { "ivg_id" }; string[] values = { objEntity.Attributes["ivg_id"].ToString() }; if (objcheck.CheckDuplicateBase(service, objEntity.LogicalName, att, values, columName)) //if (CheckDuplicateID(service, "ivg_itemtype", "ivg_id", ObjItemType.Ivg_id, "ivg_id")) { //Update Name neu ID trung //objEntity.Attributes["ivg_id"] = ObjItemType.Ivg_id; ColumnSet attributes = new ColumnSet(new string[] { "ivg_id", "ivg_name" }); GuidTemp = objcheck.IdGui; objEntity = service.Retrieve(objEntity.LogicalName, GuidTemp, attributes); objEntity.Attributes["ivg_name"] = ObjItemType.Ivg_name; service.Update(objEntity); //End Update return new Result("", true, ObjItemType.Ivg_id); } else { Guid EntityID = service.Create(objEntity); return new Result("", false, EntityID); } } catch (Exception ex) { LogError.log.Error(ex.StackTrace); return new Result(ex.StackTrace, true); } }
private void btnRead_Click(object sender, EventArgs e) { try { if (grDataFile.Rows.Count > 0) { errBuilder = new StringBuilder(); foreach (DataGridViewRow row in grDataFile.Rows) { if (!row.IsNewRow) { ItemType ObjItemType = new ItemType(); ObjItemType.Ivg_id = row.Cells[0].Value.ToString(); ObjItemType.Ivg_name = row.Cells[1].Value.ToString(); DAOProcessItemType process = new DAOProcessItemType(); Result result = process.Create(ObjItemType); if (result.isError) { flag = false; LogError.log.Error(result.BusinessObject.ToString()); errBuilder.Append(result.BusinessObject.ToString()); } else grDataFile.Rows.Remove(row); } } if (flag == false) MessageBox.Show("Có lỗi xảy ra trùng ID: \r\n" + errBuilder.ToString() + "\r\nVui lòng kiểm tra lại", "IVG", MessageBoxButtons.OK, MessageBoxIcon.Error); else { MessageBox.Show("Import File thành công", "IVG", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Không thể Import File vui lòng kiểm tra lại", "IVG", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { LogError.log.Error("Error : " + ex.StackTrace); MessageBox.Show("Có lỗi xảy ra:" + ex.StackTrace, "IVG", MessageBoxButtons.OK, MessageBoxIcon.Error); } }