Esempio n. 1
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        ///
        /// To use this handler to respond to an AWS event, reference the appropriate package from
        /// https://github.com/aws/aws-lambda-dotnet#events
        /// and change the string input parameter to the desired event type.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static string FunctionHandler(Newtonsoft.Json.Linq.JObject evnt, ILambdaContext context)
        {
            var response = evnt.ToString();

            context.Logger.Log("Complete JSON of the event is:" + evnt.ToString());
            var records = evnt.Property("Records");

            context.Logger.Log("\nRecord Array:" + records.Value);
            // TODO check to see if only one, handle multiple
            Newtonsoft.Json.Linq.JObject record = (Newtonsoft.Json.Linq.JObject)records.First[0];
            var awsRegionString = record.Property("awsRegion").Value;

            context.Logger.Log("\nAWS Region String is:" + awsRegionString);

            Newtonsoft.Json.Linq.JObject tmpObject  = (Newtonsoft.Json.Linq.JObject)record.Property("s3").Value;
            Newtonsoft.Json.Linq.JObject tmpObject2 = (Newtonsoft.Json.Linq.JObject)tmpObject.Property("bucket").Value;
            string bucketName = tmpObject2.Property("name").Value.ToString();

            context.Logger.Log("\nBucket Property Name:" + bucketName);

            tmpObject2 = (Newtonsoft.Json.Linq.JObject)tmpObject.Property("object").Value;
            string keyName = tmpObject2.Property("key").Value.ToString();

            context.Logger.Log("\nKey Property Name:" + keyName);

            // TODO assign a region based on text found
            Amazon.RegionEndpoint awsRegion = Amazon.RegionEndpoint.USEast1;


            ReadObjectDataAsync(awsRegion, bucketName, keyName).Wait();


            return(response);
        }
Esempio n. 2
0
        public static NavSalesOrder UpdateSalesOrderForNAV(ActiveUser activeUser, NavSalesOrderRequest navSalesOrder, string navAPIUrl, string navAPIUserName, string navAPIPassword, string soNumber)
        {
            NavSalesOrder navSalesOrderResponse = null;
            string        navSalesOrderJson     = string.Empty;
            string        proFlag = null;

            Newtonsoft.Json.Linq.JObject jsonObject = null;
            string serviceCall = string.Format("{0}/SalesOrder('Order', '{1}')", navAPIUrl, soNumber);

            try
            {
                NavSalesOrder     existingSalesOrderData = GetSalesOrderForNAV(navAPIUrl, navAPIUserName, navAPIPassword, soNumber);
                NetworkCredential myCredentials          = new NetworkCredential(navAPIUserName, navAPIPassword);
                HttpWebRequest    request = (HttpWebRequest)WebRequest.Create(serviceCall);
                request.Credentials             = myCredentials;
                request.KeepAlive               = false;
                request.ContentType             = "application/json";
                request.Method                  = "PATCH";
                existingSalesOrderData.DataETag = existingSalesOrderData.DataETag.Replace("W/", string.Empty);
                request.Headers.Add(HttpRequestHeader.IfMatch, existingSalesOrderData.DataETag);
                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    navSalesOrderJson = JsonConvert.SerializeObject(navSalesOrder);
                    jsonObject        = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(navSalesOrderJson);
                    jsonObject.Property("Ship_from_City").Remove();
                    jsonObject.Property("Ship_from_County").Remove();
                    navSalesOrderJson = jsonObject.ToString();
                    streamWriter.Write(navSalesOrderJson);
                }

                WebResponse response = request.GetResponse();

                using (Stream navSalesOrderResponseStream = response.GetResponseStream())
                {
                    using (TextReader navSalesOrderReader = new StreamReader(navSalesOrderResponseStream))
                    {
                        string navSalesOrderResponseString = navSalesOrderReader.ReadToEnd();

                        using (var stringReader = new StringReader(navSalesOrderResponseString))
                        {
                            navSalesOrderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <NavSalesOrder>(navSalesOrderResponseString);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                proFlag = Entities.ProFlag.H.ToString();
                _logger.Log(exp, string.Format("Error is occuring while Updating the Sales order: Request Url is: {0}, Request body json was {1}", serviceCall, navSalesOrderJson), string.Format("Sales order updation for JobId: {0}", navSalesOrder.M4PL_Job_ID), LogType.Error);
            }

            var jobIdList = new System.Collections.Generic.List <long>();

            jobIdList.Add(Convert.ToInt64(navSalesOrder.M4PL_Job_ID));
            _commands.UpdateJobProFlag(activeUser, proFlag, jobIdList, Entities.EntitiesAlias.SalesOrder);

            return(navSalesOrderResponse);
        }
Esempio n. 3
0
 /// <summary>
 /// 判断JSON 字符串 某个节点是否存在 true/false 存在/不存在
 /// </summary>
 /// <param name="jsonStr">JSON字符串</param>
 /// <param name="keyName">KYE名称</param>
 /// <returns>true/false 存在/不存在</returns>
 private bool IsJsonKey(string jsonStr, string keyName)
 {
     Newtonsoft.Json.Linq.JObject jo = Newtonsoft.Json.Linq.JObject.Parse(jsonStr);
     if (jo.Property(keyName) == null || jo.Property(keyName).ToString() == "")
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Esempio n. 4
0
        public override ValueProviderResult GetValue(string key)
        {
            object rawValue = JObject.Property(key).First();
            var    sv       = new StringValues(rawValue.ToString());

            return(new ValueProviderResult(sv, _culture));
        }
Esempio n. 5
0
        /// <summary>
        /// Create an instance of objectType, based properties in the JSON object.
        /// </summary>
        /// <param name="objectType">type of object expected, one of the derived classes from <see cref="IMessage"/></param>
        /// <param name="jObject">contents of JSON object that will be deserialized</param>
        /// <returns>An empty derived <see cref="Input"/> object that can be filled with the json data.</returns>
        protected override Input Create(Type objectType, Newtonsoft.Json.Linq.JObject jObject)
        {
            var type = (string)jObject.Property("type");

            switch (type)
            {
            //Atomic
            case "checkbox":
                return(new Checkbox());

            case "number":
                return(new Number());

            case "select":
                return(new Select());

            case "text":
                return(new Text());

            //NonAtomic
            case "inputGroup":
                return(new InputGroup());

            case "list":
                return(new List());

            case "geojson":
                return(new GeoJson());

            case "FeatureCollection":
                return(new GeoValue());
            }

            throw new ApplicationException(String.Format("The input type '{0}' is not supported!", type));
        }
        //get current currency rate
        private double GetCurrencyRate()
        {
            string    apiUrl   = "https://free.currencyconverterapi.com/api/v6/convert?q=USD_VND&compact=ultra&apiKey=5ed7e9b2743eefb282d6";
            WebClient web      = new WebClient();
            string    response = String.Empty;

            try
            {
                response = web.DownloadString(apiUrl);
            }
            catch (Exception ex)
            {
                return(-1);
            }
            Newtonsoft.Json.Linq.JObject obj = Newtonsoft.Json.Linq.JObject.Parse(response);
            string money = obj.Property("USD_VND").Value.ToString();

            try
            {
                double rate = Convert.ToDouble(money);
                return(rate);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(Convert.ToDouble(1));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Create an instance of objectType, based properties in the JSON object.
        /// </summary>
        /// <param name="objectType">type of object expected, one of the derived classes from <see cref="IMessage"/></param>
        /// <param name="jObject">contents of JSON object that will be deserialized</param>
        /// <returns>An empty derived <see cref="Output"/> object that can be filled with the json data.</returns>
        protected override Data Create(Type objectType, Newtonsoft.Json.Linq.JObject jObject)
        {
            var type = (string)jObject.Property("type");

            return(new GeoObject());

            throw new ApplicationException(String.Format("The type {0} is not supported!", type));
        }
Esempio n. 8
0
 /// <summary>
 /// 验证JSON节点是否存在
 /// </summary>
 /// <param name="jsonStr">JSON字符串</param>
 /// <param name="nodeName">节点名称</param>
 /// <returns></returns>
 public static bool IsJsonNodeName(string jsonStr, string nodeName)
 {
     try
     {
         Newtonsoft.Json.Linq.JObject jo = Newtonsoft.Json.Linq.JObject.Parse(jsonStr);
         if (jo.Property(nodeName) == null || jo.Property(nodeName).ToString() == "")
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// 判断JSON 字符串 某个节点是否存在 true/false 存在/不存在
 /// </summary>
 /// <param name="jsonStr">JSON字符串</param>
 /// <param name="keyName">KYE名称</param>
 /// <returns>true/false 存在/不存在</returns>
 private bool IsJsonKey(string jsonStr, string keyName)
 {
     try
     {
         Newtonsoft.Json.Linq.JObject jo = Newtonsoft.Json.Linq.JObject.Parse(jsonStr);
         if (jo.Property(keyName) == null || jo.Property(keyName).ToString() == "")
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        private IAuthenticationToken ReadToken(Newtonsoft.Json.Linq.JObject rawToken)
        {
            var error = rawToken.Property("error");

            if (error != null)
            {
                throw new InvalidOperationException(rawToken.Property("error_description").ToString());
            }
            var token = rawToken.ToObject <AuthenticationToken>();

            if (token.ExpiresIn.HasValue)
            {
                token.ExpirationDate = DateTime.UtcNow.AddSeconds(token.ExpiresIn.GetValueOrDefault());
            }
            else
            {
                token.ExpirationDate = DateTime.UtcNow.AddSeconds(token.SlidingWindow.GetValueOrDefault());
            }
            return(token);
        }
Esempio n. 11
0
        private static bool GetJsonValue(Newtonsoft.Json.Linq.JObject jo, string name, out Newtonsoft.Json.Linq.JToken value)
        {
            if (jo.Property(name) == null)
            {
                value = null;
                return(false);
            }

            value = jo[name];
            return(true);
        }
Esempio n. 12
0
        public void Edit(int id, string field, string oldvalue, string newvalue, object BangKH)
        {
            daKhachHang dKH = new daKhachHang();

            Newtonsoft.Json.Linq.JObject node = JSON.Deserialize <Newtonsoft.Json.Linq.JObject>(BangKH.ToString());

            dKH.KH.MaBuuCuc    = node.Property("MaBuuCuc").Value.ToString();
            dKH.KH.MaKhachHang = node.Property("MaKhachHang").Value.ToString();

            try
            {
                dKH.KH.NgayPhatSinhDoanhThu = DateTime.Parse(node.Property("NgayPhatSinhDoanhThu").Value.ToString());
                dKH.CapNhatNgay();
                grdKhachHang.GetStore().GetById(id).Commit();
            }
            catch
            {
                X.Msg.Alert("", "Nhập sai định dạng ngày!").Show();
                grdKhachHang.GetStore().GetById(id).Reject();
            }
        }
Esempio n. 13
0
        public void Edit(int id, string field, string oldvalue, string newvalue, object BangSD)
        {
            daDuCuoiTienMat dDCTM = new daDuCuoiTienMat();

            Newtonsoft.Json.Linq.JObject node = JSON.Deserialize <Newtonsoft.Json.Linq.JObject>(BangSD.ToString());
            dDCTM.TM.MaKeToanNgay = node.Property("MaKeToanNgay").Value.ToString();
            dDCTM.TM.Khoa         = bool.Parse(newvalue);
            dDCTM.TM.NguoiKhoa    = UIHelper.daPhien.TenNguoiSuDung;

            dDCTM.KhoaMo();
            stoKhoaSoDuTMCuoiNgay.Reload();
        }
Esempio n. 14
0
        public void Edit(int id, string field, string oldvalue, string newvalue, object BangCTMB)
        {
            daChiTieuMauBieu dCTMB = new daChiTieuMauBieu();

            dCTMB.CTMB.IDMauBieu = int.Parse(cboBieuBaoCao.SelectedItem.Value);
            dCTMB.CTMB.IDChiTieu = id;

            Newtonsoft.Json.Linq.JObject node = JSON.Deserialize <Newtonsoft.Json.Linq.JObject>(BangCTMB.ToString());

            try { dCTMB.CTMB.ThuTu = node.Property("ThuTu").Value.ToString(); }
            catch { }
            try { dCTMB.CTMB.InDam = Boolean.Parse(node.Property("InDam").Value.ToString()); }
            catch { dCTMB.CTMB.InDam = false; }
            try { dCTMB.CTMB.InNghieng = Boolean.Parse(node.Property("InNghieng").Value.ToString()); }
            catch { dCTMB.CTMB.InNghieng = false; }
            try { dCTMB.CTMB.STTsx = Decimal.Parse(node.Property("STTsx").Value.ToString()); }
            catch { dCTMB.CTMB.STTsx = 0; }
            try { dCTMB.CTMB.NhapTay = Boolean.Parse(node.Property("NhapTay").Value.ToString()); }
            catch { dCTMB.CTMB.NhapTay = false; }

            dCTMB.ThemSua();
            grdChiTieuMB.GetStore().GetById(id).Commit();
        }
Esempio n. 15
0
        public void EditDSNhan(int id, string field, string oldvalue, string newvalue, object BangCTMB)
        {
            if (field != "MaChiTieuDanSuat")
            {
                return;
            }
            daChiTieu dCT = new daChiTieu();

            dCT.CTTim.Ma   = newvalue;
            dCT.CTTim.Nhom = Nhom;

            daChiTieuDanSuat dDS = new daChiTieuDanSuat();

            dDS.PT.IDMauBieu = ucChiTieuMB1.IDmauBieu;
            dDS.PT.IDChiTieu = ucChiTieuMB1.IDChiTieu;

            if (newvalue == "")
            {
                dDS.PT.MaChiTieuDanSuat = oldvalue;
                dDS.XoaDanSuatNhan();
                ucChiTieuMB1.DSNhanOK(id, true);
                return;
            }

            if (dCT.Tim() == null)
            {
                ucChiTieuMB1.DSNhanOK(id, false);
                X.Msg.Alert("", "Không tìm thấy chỉ tiêu dẫn suất có mã là: " + newvalue).Show();
            }
            else
            {
                dDS.PT.IDChiTieuDanSuat = dCT.CTTim.ID;
                dDS.PT.MaChiTieuDanSuat = newvalue.ToUpper();

                Newtonsoft.Json.Linq.JObject node = JSON.Deserialize <Newtonsoft.Json.Linq.JObject>(BangCTMB.ToString());
                try
                {
                    dDS.PT.HeSo = Decimal.Parse(node.Property("HeSo").Value.ToString());
                }
                catch
                {
                    dDS.PT.HeSo = 1;
                }


                dDS.ThemDanSuatNhan();
                ucChiTieuMB1.DSNhanOK(id, true);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Create an instance of objectType, based properties in the JSON object.
        /// </summary>
        /// <param name="objectType">type of object expected, one of the derived classes from <see cref="IMessage"/></param>
        /// <param name="jObject">contents of JSON object that will be deserialized</param>
        /// <returns>An empty derived <see cref="Output"/> object that can be filled with the json data.</returns>
        protected override Output Create(Type objectType, Newtonsoft.Json.Linq.JObject jObject)
        {
            var type = (string)jObject.Property("type");

            switch (type)
            {
            case "kpi":
                return(new Kpi());

            case "geojson":
                return(new GeoJson());
            }

            throw new ApplicationException(String.Format("The output type {0} is not supported!", type));
        }
Esempio n. 17
0
        static void GetEntity(AuthenticationResult token, string entity)
        {
            using (var client = new HttpClient())
            {
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token.AccessToken);
                client.DefaultRequestHeaders.Add("Accept", "application/json;odata.metadata=none");
                string entityURI = aadResource + "/data/" + entity;
                var    response  = client.GetAsync(entityURI).Result;
                string result    = response.Content.ReadAsStringAsync().Result;
                Newtonsoft.Json.Linq.JObject jobject = Newtonsoft.Json.Linq.JObject.Parse(result);
                DataTable dtValue = (DataTable)JsonConvert.DeserializeObject(jobject.Property("value").Value.ToString(), (typeof(DataTable)));

                string tableName = "dbo." + entity;
                BulkCopy(dtValue, tableName);
            }
        }
Esempio n. 18
0
        public static Newtonsoft.Json.Linq.JObject RemovePhyscialFields(this Newtonsoft.Json.Linq.JObject jsonObject, DataTable fieldsTable)
        {
            var fields = new List <string>();

            foreach (DataColumn col in fieldsTable.Columns)
            {
                fields.Add(col.ColumnName);
            }

            foreach (var field in fields)
            {
                if (jsonObject[field] != null)
                {
                    jsonObject.Property(field).Remove();
                }
            }
            return(jsonObject);
        }
Esempio n. 19
0
        public void Edit(int id, string field, string oldvalue, string newvalue, object BangSD)
        {
            Newtonsoft.Json.Linq.JObject node = JSON.Deserialize <Newtonsoft.Json.Linq.JObject>(BangSD.ToString());

            DaDuCuoiTGNH dTGNH = new DaDuCuoiTGNH();

            dTGNH.TGNH.MaKeToanNgay = node.Property("MaKeToanNgay").Value.ToString();
            dTGNH.TGNH.MaBuuCuc     = node.Property("MaBuuCuc").Value.ToString();
            dTGNH.TGNH.Ngay         = NgayThang;

            try
            {
                dTGNH.TGNH.TCBCTapTrung = decimal.Parse(node.Property("TCBCTapTrung").Value.ToString());
            }
            catch { dTGNH.TGNH.TCBCTapTrung = 0; }
            try
            {
                dTGNH.TGNH.TCBCThanhToanTaiDonVi = decimal.Parse(node.Property("TCBCThanhToanTaiDonVi").Value.ToString());
            }
            catch { dTGNH.TGNH.TCBCThanhToanTaiDonVi = 0; }
            try
            {
                dTGNH.TGNH.TKBD = decimal.Parse(node.Property("TKBD").Value.ToString());
            }
            catch { dTGNH.TGNH.TKBD = 0; }
            try
            {
                dTGNH.TGNH.KinhDoanh = decimal.Parse(node.Property("KinhDoanh").Value.ToString());
            }
            catch { dTGNH.TGNH.KinhDoanh = 0; }
            try
            {
                dTGNH.TGNH.Cong = decimal.Parse(node.Property("Cong").Value.ToString());
            }
            catch { dTGNH.TGNH.Cong = 0; }

            dTGNH.Them();

            grdSoDuTGNHCuoiNgay.GetStore().GetById(id).Commit();
        }
Esempio n. 20
0
        public void Edit(int id, string field, string oldvalue, string newvalue, object BangSD)
        {
            Newtonsoft.Json.Linq.JObject node = JSON.Deserialize <Newtonsoft.Json.Linq.JObject>(BangSD.ToString());

            daDinhMucLuuQuy dDMLQ = new daDinhMucLuuQuy();

            dDMLQ.DMuc.MaBuuCuc = node.Property("MaBuuCuc").Value.ToString();
            dDMLQ.DMuc.GhiChu   = node.Property("GhiChu").Value.ToString();

            try
            {
                dDMLQ.DMuc.DinhMucLuuQuyTCBC = decimal.Parse(node.Property("DinhMucLuuQuyTCBC").Value.ToString());
            }
            catch { dDMLQ.DMuc.DinhMucLuuQuyTCBC = 0; }
            try
            {
                dDMLQ.DMuc.DinhMucLuuQuyTCBC_DonVi = decimal.Parse(node.Property("DinhMucLuuQuyTCBC_DonVi").Value.ToString());
            }
            catch { dDMLQ.DMuc.DinhMucLuuQuyTCBC_DonVi = 0; }
            try
            {
                dDMLQ.DMuc.DinhMucLuuQuyTKBD = decimal.Parse(node.Property("DinhMucLuuQuyTKBD").Value.ToString());
            }
            catch { dDMLQ.DMuc.DinhMucLuuQuyTKBD = 0; }
            try
            {
                dDMLQ.DMuc.DinhMucLuuQuyTKBD_DonVi = decimal.Parse(node.Property("DinhMucLuuQuyTKBD_DonVi").Value.ToString());
            }
            catch { dDMLQ.DMuc.DinhMucLuuQuyTKBD_DonVi = 0; }


            dDMLQ.ThemSua(true);


            grdDinhMucLuuQuy.GetStore().GetById(id).Commit();
        }
Esempio n. 21
0
        /// <summary>
        /// Create an instance of objectType, based properties in the JSON object.
        /// </summary>
        /// <param name="objectType">type of object expected, one of the derived classes from <see cref="IMessage"/></param>
        /// <param name="jObject">contents of JSON object that will be deserialized</param>
        /// <returns>An empty derived <see cref="IMessage"/> object that can be filled with the json data.</returns>
        protected override IMessage Create(Type objectType, Newtonsoft.Json.Linq.JObject jObject)
        {
            var type   = (string)jObject.Property("type");
            var method = (string)jObject.Property("method");

            //if (objectType == typeof(Request) & type == "request")  //Makes it possible to only get header-information (i.e. not deserialize the data)
            //    return new Request();
            //else if (objectType == typeof(Request))
            //    return null;
            //else if (objectType == typeof(Response) & type == "response")
            //    return new Response();
            //else if (objectType == typeof(Response))
            //    return null;

            switch (method)
            {
            case "getModules":
                if (type == "request")
                {
                    return(new GetModulesRequest());
                }
                else if (type == "response")
                {
                    return(new GetModulesResponse());
                }
                break;

            case "selectModule":
                if (type == "request")
                {
                    return(new SelectModuleRequest());
                }
                else if (type == "response")
                {
                    return(new SelectModuleResponse());
                }
                break;

            case "startModule":
                if (type == "request")
                {
                    return(new StartModuleRequest());
                }
                else if (type == "response")
                {
                    return(new StartModuleResponse());
                }
                break;

            case "getKpiResult":
                if (type == "request")
                {
                    return(new GetKpiResultRequest());
                }
                else if (type == "response")
                {
                    return(new GetKpiResultResponse());
                }
                break;

            case "getData":
                if (type == "request")
                {
                    return(new GetDataRequest());
                }
                else if (type == "response")
                {
                    return(new GetDataResponse());
                }
                break;

            case "setKpiResult":
                if (type == "request")
                {
                    return(new SetKpiResultRequest());
                }
                else if (type == "response")
                {
                    return(new SetKpiResultResponse());
                }
                break;

            case "moduleResult":
                if (type == "result")
                {
                    return(new ModuleResult());
                }
                break;

            default:
                return(new IMessage());

                break;
            }

            throw new ApplicationException(String.Format("The message type '{0}' or method '{1}' is not supported!", type, method));
        }
Esempio n. 22
0
        public static NavPurchaseOrder UpdatePurchaseOrderForNAV(ActiveUser activeUser, List <long> jobIdList, string poNumer, string navAPIUrl, string navAPIUserName, string navAPIPassword, bool electronicInvoice, List <PurchaseOrderItem> purchaseOrderItemRequest)
        {
            string           navPurchaseOrderJson     = string.Empty;
            string           dimensionCode            = string.Empty;
            string           divisionCode             = string.Empty;
            NavPurchaseOrder navPurchaseOrderResponse = null;
            string           proFlag = null;

            Newtonsoft.Json.Linq.JObject jsonObject = null;
            string serviceCall = string.Format("{0}/PurchaseOrder('Order', '{1}')", navAPIUrl, poNumer);

            try
            {
                NavPurchaseOrder        existingSalesOrderData  = GetPurchaseOrderForNAV(navAPIUrl, navAPIUserName, navAPIPassword, poNumer);
                NavPurchaseOrderRequest navPurchaseOrderRequest = _purchaseCommands.GetPurchaseOrderCreationData(activeUser, jobIdList, Entities.EntitiesAlias.PurchaseOrder);
                if (navPurchaseOrderRequest == null)
                {
                    return(null);
                }
                var dimensions = CommonCommands.GetSalesOrderDimensionValues(navAPIUserName, navAPIPassword, navAPIUrl);
                if (dimensions != null && dimensions.NavSalesOrderDimensionValues != null && dimensions.NavSalesOrderDimensionValues.Count > 0)
                {
                    divisionCode = dimensions.NavSalesOrderDimensionValues.Where(x => !string.IsNullOrEmpty(x.Dimension_Code) && x.Dimension_Code.ToUpper() == "DIVISION" && x.ERPId == navPurchaseOrderRequest.Sell_to_Customer_No).Any()
                                                ? dimensions.NavSalesOrderDimensionValues.Where(x => !string.IsNullOrEmpty(x.Dimension_Code) && x.Dimension_Code.ToUpper() == "DIVISION" && x.ERPId == navPurchaseOrderRequest.Sell_to_Customer_No).FirstOrDefault().Code
                                                : string.Empty;

                    if (!string.IsNullOrEmpty(navPurchaseOrderRequest.Ship_from_City) && !string.IsNullOrEmpty(navPurchaseOrderRequest.Ship_from_County))
                    {
                        string dimensionMatchCode = navPurchaseOrderRequest.Ship_from_City.Length >= 3 ? string.Format("{0}{1}", navPurchaseOrderRequest.Ship_from_City.Substring(0, 3), navPurchaseOrderRequest.Ship_from_County) : string.Empty;
                        if (!string.IsNullOrEmpty(dimensionMatchCode))
                        {
                            dimensionCode = dimensions.NavSalesOrderDimensionValues.Where(codeMatch => !string.IsNullOrEmpty(codeMatch.Code) && codeMatch.Code.Length > 4 && codeMatch.Code.Substring(codeMatch.Code.Length - 5).ToUpper() == dimensionMatchCode.ToUpper()).Any() ?
                                            dimensions.NavSalesOrderDimensionValues.Where(codeMatch => !string.IsNullOrEmpty(codeMatch.Code) && codeMatch.Code.Length > 4 && codeMatch.Code.Substring(codeMatch.Code.Length - 5).ToUpper() == dimensionMatchCode.ToUpper()).FirstOrDefault().Code : dimensionCode;
                        }
                    }
                }

                navPurchaseOrderRequest.Shortcut_Dimension_2_Code = dimensionCode;
                navPurchaseOrderRequest.Shortcut_Dimension_1_Code = divisionCode;
                navPurchaseOrderRequest.Electronic_Invoice        = electronicInvoice;
                NetworkCredential myCredentials = new NetworkCredential(navAPIUserName, navAPIPassword);
                HttpWebRequest    request       = (HttpWebRequest)WebRequest.Create(serviceCall);
                request.Credentials = myCredentials;
                request.KeepAlive   = false;
                request.ContentType = "application/json";
                request.Method      = "PATCH";
                request.Headers.Add(HttpRequestHeader.IfMatch, existingSalesOrderData.DataETag);
                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    navPurchaseOrderJson = JsonConvert.SerializeObject(navPurchaseOrderRequest);
                    jsonObject           = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(navPurchaseOrderJson);
                    jsonObject.Property("Ship_from_City").Remove();
                    jsonObject.Property("Ship_from_County").Remove();
                    navPurchaseOrderJson = jsonObject.ToString();
                    streamWriter.Write(navPurchaseOrderJson);
                }

                WebResponse response = request.GetResponse();

                using (Stream navPurchaseOrderResponseStream = response.GetResponseStream())
                {
                    using (TextReader navPurchaseOrderReader = new StreamReader(navPurchaseOrderResponseStream))
                    {
                        string responceString = navPurchaseOrderReader.ReadToEnd();

                        using (var stringReader = new StringReader(responceString))
                        {
                            navPurchaseOrderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <NavPurchaseOrder>(responceString);
                        }
                    }
                }

                if (navPurchaseOrderResponse != null && !string.IsNullOrWhiteSpace(navPurchaseOrderResponse.No))
                {
                    if (purchaseOrderItemRequest != null && purchaseOrderItemRequest.Count > 0)
                    {
                        purchaseOrderItemRequest.ForEach(x => x.Document_No = navPurchaseOrderResponse.No);
                    }

                    UpdateLineItemInformationForPurchaseOrder(activeUser, jobIdList, navAPIUrl, navAPIUserName, navAPIPassword, dimensionCode, divisionCode, navPurchaseOrderResponse.No, out proFlag, electronicInvoice, purchaseOrderItemRequest);
                }
            }
            catch (Exception exp)
            {
                proFlag = Entities.ProFlag.H.ToString();
                _logger.Log(exp, string.Format("Error is occuring while Updating the purchase order: Request Url is: {0}, Request body json was {1}", serviceCall, navPurchaseOrderJson), string.Format("Purchase order updation for JobId: {0}", Newtonsoft.Json.JsonConvert.SerializeObject(jobIdList)), LogType.Error);
            }

            _commands.UpdateJobProFlag(activeUser, proFlag, jobIdList, Entities.EntitiesAlias.PurchaseOrder);
            return(navPurchaseOrderResponse);
        }
Esempio n. 23
0
        private static void MergeJsonObjects(Newtonsoft.Json.Linq.JObject self, Newtonsoft.Json.Linq.JObject other)
        {
            foreach (var p in other.Properties())
            {
                var sp = self.Property(p.Name);
                if (sp == null)
                {
                    self.Add(p);
                }
                else
                {
                    switch (p.Type)
                    {
                    // Primitives override
                    case Newtonsoft.Json.Linq.JTokenType.Boolean:
                    case Newtonsoft.Json.Linq.JTokenType.Bytes:
                    case Newtonsoft.Json.Linq.JTokenType.Comment:
                    case Newtonsoft.Json.Linq.JTokenType.Constructor:
                    case Newtonsoft.Json.Linq.JTokenType.Date:
                    case Newtonsoft.Json.Linq.JTokenType.Float:
                    case Newtonsoft.Json.Linq.JTokenType.Guid:
                    case Newtonsoft.Json.Linq.JTokenType.Integer:
                    case Newtonsoft.Json.Linq.JTokenType.String:
                    case Newtonsoft.Json.Linq.JTokenType.TimeSpan:
                    case Newtonsoft.Json.Linq.JTokenType.Uri:
                    case Newtonsoft.Json.Linq.JTokenType.None:
                    case Newtonsoft.Json.Linq.JTokenType.Null:
                    case Newtonsoft.Json.Linq.JTokenType.Undefined:
                        self.Replace(p);
                        break;

                    // Arrays merge
                    case Newtonsoft.Json.Linq.JTokenType.Array:
                        if (sp.Type == Newtonsoft.Json.Linq.JTokenType.Array)
                        {
                            sp.Value = new Newtonsoft.Json.Linq.JArray(((Newtonsoft.Json.Linq.JArray)sp.Value).Union((Newtonsoft.Json.Linq.JArray)p.Value));
                        }
                        else
                        {
                            var a = new Newtonsoft.Json.Linq.JArray(sp.Value);
                            sp.Value = new Newtonsoft.Json.Linq.JArray(a.Union((Newtonsoft.Json.Linq.JArray)p.Value));
                        }

                        break;

                    // Objects merge
                    case Newtonsoft.Json.Linq.JTokenType.Object:
                        if (sp.Type == Newtonsoft.Json.Linq.JTokenType.Object)
                        {
                            MergeJsonObjects((Newtonsoft.Json.Linq.JObject)sp.Value, (Newtonsoft.Json.Linq.JObject)p.Value);
                        }
                        else
                        {
                            sp.Value = p.Value;
                        }
                        break;

                    // Ignore other stuff
                    default:
                        break;
                    }
                }
            }
        }
Esempio n. 24
0
        public void Edit(int id, string field, string oldvalue, string newvalue, object BangSD)
        {
            Newtonsoft.Json.Linq.JObject node = JSON.Deserialize <Newtonsoft.Json.Linq.JObject>(BangSD.ToString());

            if (field.Substring(0, 2) == "dk")
            {
                daDuKienChiTra dDKCT = new daDuKienChiTra();
                dDKCT.DKCTra.MaKeToanNgay = node.Property("MaKeToanNgay").Value.ToString();
                dDKCT.DKCTra.MaBuuCuc     = node.Property("MaBuuCuc").Value.ToString();
                dDKCT.DKCTra.Ngay         = DateTime.Parse(node.Property("Ngay").Value.ToString());

                try
                {
                    dDKCT.DKCTra.TCBCTapTrung = decimal.Parse(node.Property("dkTCBCTapTrung").Value.ToString());
                }
                catch { dDKCT.DKCTra.TCBCTapTrung = 0; }
                try
                {
                    dDKCT.DKCTra.TCBCThanhToanTaiDonVi = decimal.Parse(node.Property("dkTCBCThanhToanTaiDonVi").Value.ToString());
                }
                catch { dDKCT.DKCTra.TCBCThanhToanTaiDonVi = 0; }
                try
                {
                    dDKCT.DKCTra.TKBD = decimal.Parse(node.Property("dkTKBD").Value.ToString());
                }
                catch { dDKCT.DKCTra.TKBD = 0; }
                try
                {
                    dDKCT.DKCTra.KinhDoanh = decimal.Parse(node.Property("dkKinhDoanh").Value.ToString());
                }
                catch { dDKCT.DKCTra.KinhDoanh = 0; }
                try
                {
                    dDKCT.DKCTra.Cong = decimal.Parse(node.Property("dkCong").Value.ToString());
                }
                catch { dDKCT.DKCTra.Cong = 0; }

                dDKCT.ThemSua();
            }
            else
            {
                daDuCuoiTienMat dDC = new daDuCuoiTienMat();
                dDC.TM.MaKeToanNgay = node.Property("MaKeToanNgay").Value.ToString();
                dDC.TM.MaBuuCuc     = node.Property("MaBuuCuc").Value.ToString();
                dDC.TM.Ngay         = DateTime.Parse(node.Property("Ngay").Value.ToString());

                try
                {
                    dDC.TM.TCBCTapTrung = decimal.Parse(node.Property("TCBCTapTrung").Value.ToString());
                }
                catch { dDC.TM.TCBCTapTrung = 0; }
                try
                {
                    dDC.TM.TCBCThanhToanTaiDonVi = decimal.Parse(node.Property("TCBCThanhToanTaiDonVi").Value.ToString());
                }
                catch { dDC.TM.TCBCThanhToanTaiDonVi = 0; }
                try
                {
                    dDC.TM.TKBD = decimal.Parse(node.Property("TKBD").Value.ToString());
                }
                catch { dDC.TM.TKBD = 0; }
                try
                {
                    dDC.TM.KinhDoanh = decimal.Parse(node.Property("KinhDoanh").Value.ToString());
                }
                catch { dDC.TM.KinhDoanh = 0; }
                try
                {
                    dDC.TM.Cong = decimal.Parse(node.Property("Cong").Value.ToString());
                }
                catch { dDC.TM.Cong = 0; }

                dDC.ThemSua();
            }

            grdSoDuTMCuoiNgay.GetStore().GetById(id).Commit();
        }