Exemple #1
0
        protected void btSave_Click(object sender, EventArgs e)
        {
            ProduceBOM    info = new ProduceBOM();
            ProduceDOMBLL bll  = null;

            try
            {
                UIBindHelper.BindModelByControls(this.Page, info);

                bll = BLLFactory.CreateBLL <ProduceDOMBLL>();

                info.Details = JsonConvertHelper.DeserializeObject <List <BOMDetail> >(this.hiBomDetailList.Value);

                if (this.hiID.Value == "")
                {
                    bll.Insert(info);
                }
                else
                {
                    info.CREATEUSER = this.HiCREATEUSER.Value;
                    info.CREATETIME = DateTime.Parse(this.HiCREATETIME.Value);
                    info.PID        = this.hiID.Value;
                    bll.Update(info);
                }
                ClientScript.RegisterStartupScript(this.GetType(), "myjs", "parent.refreshData();parent.closeAppWindow1();", true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected virtual async Task <List <TModel> > Query(string key = "")
        {
            string queryUri = $"{ConfigHelper.WebAPIAddress}/{this.ModelType.Name}/Query?key={key}";

            LogHelper <TModel> .Debug($"查询地址:{queryUri}");

            try
            {
                using (var response = await WebHelper.GetAsync(queryUri))
                {
                    LogHelper <TModel> .Debug($"接收到响应数据,状态代码:{response.StatusCode}");

                    if (response.IsSuccessStatusCode)
                    {
                        string content = await response.Content.ReadAsStringAsync();

                        var models = JsonConvertHelper.DeserializeObject <List <TModel> >(content);

                        LogHelper <TModel> .Debug($"接收到 {models.Count} 条数据。");

                        return(models);
                    }
                    else
                    {
                        return(default);
Exemple #3
0
        protected void btSave_Click(object sender, EventArgs e)
        {
            SupplyInfo    info = new SupplyInfo();
            SupplyInfoBLL bll  = null;

            try
            {
                UIBindHelper.BindModelByControls(this.Page, info);

                bll = BLLFactory.CreateBLL <SupplyInfoBLL>();

                info.Details = JsonConvertHelper.DeserializeObject <List <SupplyMaterialInfo> >(this.hiMaterialList.Value);

                info.BATCHNUMBER = this.PLANID.SelectedItem.Text;
                if (this.hiID.Value == "")
                {
                    bll.Insert(info);
                }
                else
                {
                    info.CREATEUSER = this.HiCREATEUSER.Value;
                    info.CREATETIME = DateTime.Parse(this.HiCREATETIME.Value);
                    info.PID        = this.hiID.Value;
                    info.PLANID     = this.hiPlanID.Value;
                    info.PLName     = this.PLNAME.Text;
                    bll.Update(info);
                }
                ClientScript.RegisterStartupScript(this.GetType(), "myjs", "parent.refreshData();parent.closeAppWindow1();", true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        public void TestUpdateAppliedMigrationsExistingPrefix()
        {
            _rabbitMqHistory.Init();
            SetupDefaultExchange();

            PushDummyMigrationHistoryMessage();
            var migrationHistoryRow = new MigrationHistoryRow {
                Prefix = "test"
            };

            migrationHistoryRow.AppliedMigrations.Add(new MigrationHistoryRowDetails {
                Name = "001_TestMigration"
            });
            migrationHistoryRow.AppliedMigrations.Add(new MigrationHistoryRowDetails {
                Name = "002_TestMigrationAddQueue"
            });

            _rabbitMqHistory.UpdateAppliedMigrations(migrationHistoryRow);

            using (var connection = _connectionFactory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var message = channel.BasicGet(Constants.HistoryQueue, true);
                    Assert.IsNotNull(message);

                    var migrationHistory = JsonConvertHelper.DeserializeObject <MigrationHistory>(message.Body);
                    Assert.IsNotNull(migrationHistory);
                    Assert.AreEqual(1, migrationHistory.AllMigrations.Count);
                    var migration = migrationHistory.AllMigrations.First();
                    Assert.AreEqual("test", migration.Prefix);
                    Assert.AreEqual(2, migration.AppliedMigrations.Count);
                    CollectionAssert.AreEqual(migrationHistoryRow.AppliedMigrations.ToList(), migration.AppliedMigrations.ToList(), new AppliedMigrationsComparer());
                }
        }
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btConfirm_Click(object sender, EventArgs e)
        {
            CheckStockBill info = new CheckStockBill();
            CheckStockBLL  bll  = null;

            try
            {
                UIBindHelper.BindModelByControls(this.Page, info);

                bll = BLLFactory.CreateBLL <CheckStockBLL>();

                info.Details = JsonConvertHelper.DeserializeObject <List <CheckStockDetail> >(this.hiCheckList.Value);

                info.CREATEUSER = this.HiCREATEUSER.Value;
                info.CREATETIME = DateTime.Parse(this.HiCREATETIME.Value);
                info.ID         = this.hiID.Value;
                bll.ConfirmCheck(info);

                ClientScript.RegisterStartupScript(this.GetType(), "myjs", "parent.refreshData();parent.closeAppWindow1();", true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> Add([FromForm] string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                this.logger.LogWarning($"{this.HttpContext.Connection.RemoteIpAddress} 请求新增空数据的 {typeof(TModel).Name} 对象");

                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity));
            }

            try
            {
                var model = JsonConvertHelper.DeserializeObject <TModel>(value);
                if (model == null)
                {
                    this.logger.LogWarning($"{this.HttpContext.Connection.RemoteIpAddress} 请求新增的数据转义为 {typeof(TModel).Name} 对象为空引用");

                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity));
                }

                await this.context.Set <TModel>().AddAsync(model);

                await this.context.SaveChangesAsync();

                this.logger.LogDebug($"{this.HttpContext.Connection.RemoteIpAddress} 请求新增 ID 为 {model.ID} 的 {typeof(TModel).Name} 对象");
                return(this.StatusCode(StatusCodes.Status201Created, model.ID));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, $"{this.HttpContext.Connection.RemoteIpAddress} 请求新增 {typeof(TModel).Name} 对象遇到异常");

                return(this.StatusCode(StatusCodes.Status417ExpectationFailed, ex.Message));
            }
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static List <TableModel> GetListTable()
        {
            string filepath = "table.json";
            string json     = JsonHelper.GetFile(filepath);

            List <TableModel> tableModels = JsonConvertHelper.DeserializeObject <List <TableModel> >(json) as List <TableModel>;

            return(tableModels);
        }
Exemple #8
0
        public async Task <User> Get()
        {
            HttpRequestItem httpRequestItem = new HttpRequestItem()
            {
                Url             = Url,
                HttpMethod      = HttpMethod.Get,
                AuthHeaderValue = new AuthenticationHeaderValue("Bearer", AccessToken)
            };

            HttpResponseMessage httpResponseMessage = await _requestHandler.RequestAsync(httpRequestItem);

            string content = await httpResponseMessage.Content.ReadAsStringAsync();

            User user = JsonConvertHelper.DeserializeObject <User>(content);

            return(user);
        }
Exemple #9
0
        public async Task <Expense> Get(int expenseId)
        {
            HttpRequestItem httpRequestItem = new HttpRequestItem()
            {
                Url             = "https://api.toshl.com/expenses/" + expenseId,
                HttpMethod      = HttpMethod.Get,
                AuthHeaderValue = new AuthenticationHeaderValue("Bearer", AccessToken)
            };

            HttpResponseMessage httpResponseMessage = await _requestHandler.RequestAsync(httpRequestItem);

            string content = await httpResponseMessage.Content.ReadAsStringAsync();

            Expense expense = JsonConvertHelper.DeserializeObject <Expense>(content);

            return(expense);
        }
        private static MigrationHistory EnsureLatestMigrationHistoryVersion(string migrationHistoryJson)
        {
            var migrationHistory = JsonConvertHelper.DeserializeObject <GenericMigrationHistory>(migrationHistoryJson);

            switch (migrationHistory.Version)
            {
            case 1:
                // v1 uses the default JSON Serializer settings
                var migrationHistoryV1 = JsonConvert.DeserializeObject <Objects.v1.MigrationHistory>(migrationHistoryJson);
                return(MigrationHistoryUpgradeHelper.UpgradeToV2(migrationHistoryV1));

            case 2:
                return(JsonConvertHelper.DeserializeObject <MigrationHistory>(migrationHistoryJson));

            default:
                throw new RabbitMqMigrationException($"Invalid RabbitMq History version {migrationHistory.Version}");
            }
        }
Exemple #11
0
        public async Task <User> Put(User user)
        {
            HttpRequestItem httpRequestItem = new HttpRequestItem()
            {
                Url                     = Url,
                HttpMethod              = HttpMethod.Put,
                AuthHeaderValue         = new AuthenticationHeaderValue("Bearer", AccessToken),
                HttpContent             = new FormUrlEncodedContent(JsonConvertHelper.SerializeToDictionary(user)),
                IfUnmodifiedSinceHeader = new DateTime(2014, 08, 02)
            };

            HttpResponseMessage httpResponseMessage = await _requestHandler.RequestAsync(httpRequestItem);

            string content = await httpResponseMessage.Content.ReadAsStringAsync();

            User updatedUser = JsonConvertHelper.DeserializeObject <User>(content);

            return(updatedUser);
        }
Exemple #12
0
        protected void btSave_Click(object sender, EventArgs e)
        {
            OutStockBill info   = new OutStockBill();
            OutStockBLL  bll    = null;
            string       result = null;

            try
            {
                UIBindHelper.BindModelByControls(this.Page, info);

                bll = BLLFactory.CreateBLL <OutStockBLL>();

                info.Details = JsonConvertHelper.DeserializeObject <List <OutStockDetail> >(this.hiMatList.Value);

                if (this.hiID.Value == "")
                {
                    result = bll.OutStorage(info);
                }
                else
                {
                    info.CREATEUSER = this.HiCREATEUSER.Value;
                    info.CREATETIME = DateTime.Parse(this.HiCREATETIME.Value);
                    info.ID         = this.hiID.Value;
                    bll.Update(info);
                }
                if (string.IsNullOrEmpty(result) == true)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "myjs", "parent.refreshData();parent.closeAppWindow1();", true);
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "myjs", "MSI('提示','" + result + "');", true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #13
0
        private async Task <OAuthToken> RequestToken(Dictionary <string, string> requestContent)
        {
            HttpClientHandler handler = new HttpClientHandler();
            HttpClient        client  = new HttpClient(handler);

            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue(
                    "Basic",
                    Convert.ToBase64String(
                        Encoding.GetEncoding("ISO-8859-1").GetBytes(
                            string.Format("{0}:{1}", ToshlClient.Id, ToshlClient.Secret))));

            HttpRequestMessage httpRequest = new HttpRequestMessage()
            {
                RequestUri = new Uri("https://toshl.com/oauth2/token"),
                Method     = HttpMethod.Post,
                Content    = new FormUrlEncodedContent(requestContent)
            };

            HttpResponseMessage httpResponseMessage = await client.SendAsync(httpRequest);

            string content = await httpResponseMessage.Content.ReadAsStringAsync();

            Dictionary <string, dynamic> dict = JsonConvertHelper.DeserializeObject <Dictionary <string, dynamic> >(content);

            OAuthToken oAuthToken = new OAuthToken()
            {
                AccessToken  = dict["access_token"],
                TokenType    = dict["token_type"],
                ExpiresIn    = dict["expires_in"],
                RefreshToken = dict["refresh_token"],
                Scope        = dict["scope"]
            };

            return(oAuthToken);
        }
Exemple #14
0
        /// <summary>
        /// 保存采集数据
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool saveItemAndCalResultData(string dataStr, string resDataStr)
        {
            int count = 0;
            List <InspectItemData>         itemList         = JsonConvertHelper.DeserializeObject <List <InspectItemData> >(dataStr);
            List <InspectRealTimeItemData> realTimeItemList = JsonConvertHelper.DeserializeObject <List <InspectRealTimeItemData> >(dataStr);
            List <InspectResultData>       culResultList    = JsonConvertHelper.DeserializeObject <List <InspectResultData> >(resDataStr);

            //用于事务处理
            using (IDataSession session = AppDataFactory.CreateMainSession())
            {
                try
                {
                    //插入基本信息
                    count = session.Insert <InspectItemData>(itemList);
                    foreach (InspectRealTimeItemData irti in realTimeItemList)
                    {
                        List <DataParameter> dataParameter = new List <DataParameter>();
                        dataParameter.Add(new DataParameter {
                            ParameterName = "DeviceSN", DataType = DbType.String, Value = irti.DeviceSN
                        });
                        dataParameter.Add(new DataParameter {
                            ParameterName = "ItemCode", DataType = DbType.String, Value = irti.ItemCode
                        });
                        //更新实时记录表
                        int updCount = Convert.ToInt32(session.ExecuteSqlScalar("select count(0) from inspectrealtimedata where DeviceCode = @DeviceSN and ItemCode = @ItemCode ", dataParameter.ToArray()));
                        //如果返回数据为0说明记录不存在则插入一条新的记录
                        if (updCount == 0)
                        {
                            session.Insert(irti);
                        }
                        else
                        {
                            //更新值
                            dataParameter.Add(new DataParameter {
                                ParameterName = "InspectTime", DataType = DbType.DateTime, Value = irti.InspectTime
                            });
                            dataParameter.Add(new DataParameter {
                                ParameterName = "InspectData", DataType = DbType.String, Value = irti.InspectData
                            });
                            dataParameter.Add(new DataParameter {
                                ParameterName = "UpdateTime", DataType = DbType.DateTime, Value = irti.UpdateTime
                            });
                            session.ExecuteSqlScalar("update inspectrealtimedata set InspectTime = @InspectTime, InspectData = @InspectData, UpdateTime = @UpdateTime where DeviceCode = @DeviceSN and ItemCode = @ItemCode ", dataParameter.ToArray());
                        }
                    }

                    //测试时使用否则插入同一张表中数据会主键冲突
                    foreach (InspectResultData ird in culResultList)
                    {
                        List <DataParameter> dataParameter = new List <DataParameter>();
                        dataParameter.Add(new DataParameter {
                            ParameterName = "ID", DataType = DbType.String, Value = ird.ID
                        });
                        int dataCount = Convert.ToInt32(session.ExecuteSqlScalar("select count(0) from inspectcalcresult where ID = @ID ", dataParameter.ToArray()));
                        //如果返回数据为0说明记录不存在则插入一条新的记录
                        if (dataCount == 0)
                        {
                            count += session.Insert(ird);
                        }
                        else
                        {
                            count += session.Update(ird);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    //保存出错时回滚数据
                    session.RollbackTs();
                    return(false);
                }
            }

            return(true);
        }