コード例 #1
0
        /// <summary>
        /// convert part model to part master for update part master
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IV00101_Part_Master ConvertToUpdateMaster(PartOperationModel model)
        {
            IV00101_Part_Master partMaster = new IV00101_Part_Master();

            var _partStatusRepository = new PartStatusRepository();

            var partStatus = _partStatusRepository.GetPartStatus(model.PartStatusId);

            var active = (partStatus != null && (!partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("inactive") ||
                                                 !partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("archive") ||
                                                 !partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("purge"))) ? true : false;

            partMaster.ITEMNMBR = model.PartNumber;
            partMaster.ITEMDESC = model.PartDescription;
            partMaster.ITEMSHWT = Convert.ToInt32(model.Weight * 100.00m);
            partMaster.STNDCOST = model.Cost;
            partMaster.LOCNCODE = model.SiteId;
            partMaster.INACTIVE = Convert.ToByte(active);
            partMaster.ITMCLSCD = "STANDRRD";

            if (_partStatusRepository != null)
            {
                _partStatusRepository.Dispose();
                _partStatusRepository = null;
            }

            return(partMaster);
        }
コード例 #2
0
        /// <summary>
        /// update part master
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public OperationResult UpdatePartMaster(IV00101_Part_Master part)
        {
            var operationResult = new OperationResult();

            var existingPart = _dynamicsContext.IV00101_Part_Master.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == part.ITEMNMBR.Replace(" ", string.Empty).ToLower());

            if (existingPart != null)
            {
                logger.Debug("Part Master is being updated.");

                using (eConnectMethods e = new eConnectMethods())
                {
                    try
                    {
                        using (SqlConnection connection = new SqlConnection(_dynamicsConnection))
                        {
                            connection.Open();

                            SqlCommand cmd = new SqlCommand("UPDATE dbo.IV00101 SET STNDCOST = @StandardCost, ITEMSHWT = @Weight WHERE ITEMNMBR = @ItemNumber");
                            cmd.CommandType = CommandType.Text;
                            cmd.Connection  = connection;
                            cmd.Parameters.AddWithValue("@ItemNumber", part.ITEMNMBR);
                            cmd.Parameters.AddWithValue("@StandardCost", part.STNDCOST);
                            cmd.Parameters.AddWithValue("@Weight", part.ITEMSHWT);
                            cmd.ExecuteNonQuery();

                            connection.Close();
                        }

                        operationResult.Success = true;
                        operationResult.Message = "Success";
                    }
                    // Catch any system error that might occurr.
                    // display the error message on the console
                    catch (System.Exception ex)
                    {
                        Console.Write(ex.ToString());
                        operationResult.Success = false;
                        operationResult.Message = "Error";
                        logger.ErrorFormat("Error updating part currency: {0} ", ex.ToString());
                    }
                } // end of using statement
            }
            else
            {
                operationResult.Success = false;
                operationResult.Message = "Unable to find selected part currency.";
            }

            return(operationResult);
        }
コード例 #3
0
        /// <summary>
        /// convert project part to part master
        /// </summary>
        /// <param name="projectPart"></param>
        /// <returns></returns>
        public IV00101_Part_Master ConvertToCreateMaster(ProjectPart projectPart)
        {
            IV00101_Part_Master part = new IV00101_Part_Master();

            part.ITEMNMBR = projectPart.Number;
            part.ITEMDESC = projectPart.Description;
            part.ITEMSHWT = Convert.ToInt32(projectPart.Weight * 100.00m);
            part.STNDCOST = projectPart.Cost;
            part.LOCNCODE = projectPart.SiteId;
            part.ITMCLSCD = "STANDARD";
            part.PRICMTHD = 2;
            part.INACTIVE = 0;

            return(part);
        }
コード例 #4
0
        /// <summary>
        /// get part master by item number
        /// </summary>
        /// <param name="itemNumber"></param>
        /// <returns></returns>
        public IV00101_Part_Master GetPartMaster(string itemNumber)
        {
            var part = new IV00101_Part_Master();

            try
            {
                part = _dynamicsContext.IV00101_Part_Master.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == itemNumber.Replace(" ", string.Empty).ToLower());
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting master part: {0} ", ex.ToString());
            }

            return(part);
        }
コード例 #5
0
        /// <summary>
        /// save new part master
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public OperationResult SavePartMaster(IV00101_Part_Master part)
        {
            var operationResult = new OperationResult();

            var existingPart = _dynamicsContext.IV00101_Part_Master.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == part.ITEMNMBR.Replace(" ", string.Empty).ToLower());

            if (existingPart == null)
            {
                logger.Debug("Master Part is being created...");

                using (eConnectMethods e = new eConnectMethods())
                {
                    try
                    {
                        // Instantiate a taUpdateCreateItemRcd XML node object
                        taUpdateCreateItemRcd item = new taUpdateCreateItemRcd();

                        //Populate elements of the taUpdateCreateItemRcd XML node object
                        item.ITEMNMBR       = part.ITEMNMBR;
                        item.ITEMDESC       = part.ITEMDESC;
                        item.UseItemClass   = 1;
                        item.ITMCLSCD       = part.ITMCLSCD;
                        item.UpdateIfExists = 0;

                        // Instantiate a IVItemMasterType schema object
                        IVItemMasterType itemtype = new IVItemMasterType();

                        // Populate the IVItemMasterType schema with the taUpdateCreateItemRcd XML node
                        itemtype.taUpdateCreateItemRcd = item;
                        IVItemMasterType[] itemMaster = { itemtype };

                        // Instantiate an eConnectType schema object
                        eConnectType eConnect = new eConnectType();

                        // Instantiate a Memory Stream object
                        MemoryStream memoryStream = new MemoryStream();

                        // Create an XML serializer object
                        XmlSerializer serializer = new XmlSerializer(eConnect.GetType());

                        // Populate the eConnectType object with the IVItemMasterType schema object
                        eConnect.IVItemMasterType = itemMaster;

                        // Serialize the eConnectType.
                        serializer.Serialize(memoryStream, eConnect);

                        // Reset the position of the memory stream to the start.
                        memoryStream.Position = 0;

                        // Create an XmlDocument from the serialized eConnectType in memory.
                        XmlDocument xmlDocument = new XmlDocument();
                        xmlDocument.Load(memoryStream);
                        memoryStream.Close();

                        // Call eConnect to process the XmlDocument.
                        e.CreateEntity(_dynamicsConnection, xmlDocument.OuterXml);

                        operationResult.Success = true;
                        operationResult.Message = "Success";
                    }
                    // The eConnectException class will catch eConnect business logic errors.
                    // display the error message on the console
                    catch (eConnectException exc)
                    {
                        Console.Write(exc.ToString());
                        operationResult.Success = false;
                        operationResult.Message = "Error";
                        logger.ErrorFormat("Error saving new part: {0} ", exc.ToString());
                    }
                    // Catch any system error that might occurr.
                    // display the error message on the console
                    catch (System.Exception ex)
                    {
                        Console.Write(ex.ToString());
                        operationResult.Success = false;
                        operationResult.Message = "Error";
                        logger.ErrorFormat("Error saving new part: {0} ", ex.ToString());
                    }
                    finally
                    {
                        // Call the Dispose method to release the resources
                        // of the eConnectMethds object
                        e.Dispose();
                    }
                } // end of using statement
            }
            else
            {
                operationResult.Success = false;
                operationResult.Message = "Duplicate Entry";
            }

            return(operationResult);
        }