Exemplo n.º 1
0
        public Result Create(Itemgroup ObjItemgroup)
        {
            try
            {
                if (service == null)
                {
                    LogError.log.Error("Service is null");
                    throw new Exception("Service is null");
                }
                //lay ve Entity TYPE
                QueryExpression query = new QueryExpression("ivg_itemtype");
                query.Criteria.AddCondition("ivg_id", ConditionOperator.Equal, ObjItemgroup.Ivg_itemtypeid);
                query.ColumnSet = new ColumnSet(true);
                EntityCollection entityes= service.RetrieveMultiple(query);
                Entity type = entityes.Entities[0];

                Entity objEntity = new Entity("ivg_itemgroup");
                objEntity.Attributes["ivg_itemtypeid"] = new EntityReference("ivg_itemtype", type.Id);
                objEntity.Attributes["ivg_groupid"] = ObjItemgroup.Ivg_groupid;
                objEntity.Attributes["ivg_name"] = ObjItemgroup.Ivg_name;
                OutIDcheck = new StringBuilder();
                if (CheckDuplicateGroupID(service, "ivg_itemgroup", "ivg_groupid", ObjItemgroup.Ivg_groupid, "ivg_groupid"))
                {
                    //update cac truong lien quan neu trung
                    ColumnSet attributes = new ColumnSet(new string[] { "ivg_groupid", "ivg_itemtypeid", "ivg_itemtypeid", "ivg_name" });
                    GuidTemp=Guid.Parse(OutIDcheck.ToString());
                    objEntity = service.Retrieve(objEntity.LogicalName, GuidTemp, attributes);
                    objEntity.Attributes["ivg_name"] = ObjItemgroup.Ivg_name;
                    service.Update(objEntity);
                    OutIDcheck.Clear();
                    //End Update
                    return new Result("", true, ObjItemgroup.Ivg_groupid);
                }
                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);
            }
        }
Exemplo n.º 2
0
        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)
                        {
                            Itemgroup ObjItemgroup = new Itemgroup();
                            ObjItemgroup.Ivg_itemtypeid = row.Cells[0].Value.ToString();
                            ObjItemgroup.Ivg_item_type = row.Cells[1].Value.ToString();
                            ObjItemgroup.Ivg_groupid = row.Cells[2].Value.ToString();
                            ObjItemgroup.Ivg_name = row.Cells[3].Value.ToString();

                            DAOProcessItemGroup process = new DAOProcessItemGroup();
                            Result result = process.Create(ObjItemgroup);
                            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);
            }
        }