Exemple #1
0
        public string OperatorPosListSave(string list_name, string list_id)
        {
            var operatorPosListResponse = new OperatorPosListResponse();

            try
            {
                var data = new OperatorPosListCreateRequest
                {
                    Operator    = JwtProps.GetOperator(),
                    PosList     = list_id.Split(',').Select(n => Convert.ToInt32(n)).ToList(),
                    PosListName = list_name
                };
                HttpResponseMessage responseMessage = HttpClientService.PostAsync("api/pos/SaveOperatorPosList", data).Result;
                if (responseMessage.IsSuccessStatusCode)
                {
                    operatorPosListResponse = responseMessage.Content.ReadAsAsync <OperatorPosListResponse>().Result;
                    if (operatorPosListResponse.ErrorCode == 0 && string.IsNullOrEmpty(operatorPosListResponse.Message))
                    {
                        return(JsonConvert.SerializeObject(new { success = true }));
                    }
                    return(JsonConvert.SerializeObject(operatorPosListResponse));
                }
                operatorPosListResponse.ErrorCode = 10;
                operatorPosListResponse.Message   = "Ошибка получения данных";
            }
            catch (Exception ex)
            {
                operatorPosListResponse.ErrorCode = 2;
                operatorPosListResponse.Message   = ex.Message;
            }
            return(JsonConvert.SerializeObject(operatorPosListResponse));
        }
Exemple #2
0
        /// <summary>
        /// Сохраняет список магазинов в БД
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public OperatorPosListResponse SaveOperatorPosList(OperatorPosListCreateRequest request)
        {
            var returnValue = new OperatorPosListResponse();

            _cnn.Open();
            SqlCommand cmd = _cnn.CreateCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "OperatorCreatePosList";
            cmd.Parameters.AddWithValue("@caption", request.PosListName);
            cmd.Parameters.AddWithValue("@operator", request.Operator);
            cmd.Parameters.Add("@errormessage", SqlDbType.NVarChar, 100);
            cmd.Parameters["@errormessage"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@result", SqlDbType.Int);
            cmd.Parameters["@result"].Direction = ParameterDirection.ReturnValue;

            if (request.PosList != null && request.PosList.Count > 0)
            {
                using (var table = new DataTable())
                {
                    table.Columns.Add("id", typeof(int));

                    foreach (var item in request.PosList)
                    {
                        DataRow row = table.NewRow();
                        row["id"] = item;
                        table.Rows.Add(row);
                    }
                    var items = new SqlParameter("@items", SqlDbType.Structured)
                    {
                        TypeName = "dbo.IdItem",
                        Value    = table
                    };
                    cmd.Parameters.Add(items);
                }
            }
            try
            {
                cmd.ExecuteNonQuery();
                returnValue.ErrorCode = Convert.ToInt32(cmd.Parameters["@result"].Value);
                returnValue.Message   = Convert.ToString(cmd.Parameters["@errormessage"].Value);
            }
            catch (Exception e)
            {
                returnValue.ErrorCode = 3;
                returnValue.Message   = e.Message;
            }
            finally
            {
                _cnn.Close();
            }
            return(returnValue);
        }
Exemple #3
0
        public string GetListOfPos()
        {
            OperatorPosListResponse operatorPosResponse = new OperatorPosListResponse();

            try
            {
                OperatorPosRequest operatorPosRequest = new OperatorPosRequest
                {
                    Operator = JwtProps.GetOperator()
                };
                HttpResponseMessage responseMessage = HttpClientService.PostAsync("api/pos/OperatorPosList", operatorPosRequest).Result;
                if (responseMessage.IsSuccessStatusCode)
                {
                    operatorPosResponse = responseMessage.Content.ReadAsAsync <OperatorPosListResponse>().Result;
                    if (operatorPosResponse.ErrorCode == 0 && string.IsNullOrEmpty(operatorPosResponse.Message))
                    {
                        PosModel.PosListData data = new PosModel.PosListData();
                        int i = 0;
                        foreach (var c in operatorPosResponse.PosLists)
                        {
                            i++;
                            #region Формируем выпадающий список для списка ТТ
                            var detailList = c.Poses.Aggregate(string.Empty, (current, pos) => current + (@"<tr>
                                        <td colspan='2' style='color:#000;'>" + pos.City + @"</td>
                                        <td colspan='2' style='color:#000;'>" + pos.Address + @"</td>
                                      </tr>"));
                            #endregion
                            Implementation.Data.OperatorPosList g = new Implementation.Data.OperatorPosList
                            {
                                Id            = c.Id,
                                Caption       = c.Caption,
                                Text          = c.Poses.Count().ToString(),
                                Poses         = c.Poses,
                                HtmlForDelete = "<img class='dell-control' data-id=" + c.Id + " src='/img/dell.png'>",
                                details       = detailList
                            };
                            data.data.Add(g);
                        }
                        return(JsonConvert.SerializeObject(data));
                    }
                    return(JsonConvert.SerializeObject(operatorPosResponse));
                }
                operatorPosResponse.ErrorCode = 10;
                operatorPosResponse.Message   = "Ошибка получения данных";
            }
            catch (Exception ex)
            {
                operatorPosResponse.ErrorCode = 2;
                operatorPosResponse.Message   = ex.Message;
            }
            return(JsonConvert.SerializeObject(operatorPosResponse));
        }
Exemple #4
0
        /// <summary>
        /// Получает список списков магазинов оператора"
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public OperatorPosListResponse GetPosListByOperator(OperatorPosListCreateRequest request)
        {
            var response = new OperatorPosListResponse();

            _cnn.Open();
            SqlCommand cmd = _cnn.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select id, caption, operator from poslist where operator=@id";
            cmd.Parameters.AddWithValue("@id", request.Operator);

            var result = new List <OperatorPosList>();
            var buf    = new List <OperatorPosList>();

            try
            {
                #region Получаем списки магазинов, созданных оператором
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var posList = new OperatorPosList {
                        Id = reader.GetInt16(0)
                    };
                    if (!reader.IsDBNull(1))
                    {
                        posList.Caption = reader.GetString(1);
                    }
                    if (!reader.IsDBNull(2))
                    {
                        posList.Operator = reader.GetInt16(2);
                    }
                    buf.Add(posList);
                }
                reader.Close();
                #endregion

                #region Получаем содержимое списков магазинов
                cmd.CommandText =
                    @"select p.id, c.name, p.address from poslistitems pli 
                    join poslist pl on pl.id = pli.poslist and pl.id=@id 
                    join pos p on p.id = pli.pos 
                    join city c on c.id=p.city";

                foreach (var item in buf)
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@id", item.Id);
                    var listOfPos = new List <Pos>();
                    reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var pos = new Pos {
                            Id = reader.GetInt16(0)
                        };
                        if (!reader.IsDBNull(1))
                        {
                            pos.City = reader.GetString(1);
                        }
                        if (!reader.IsDBNull(2))
                        {
                            pos.Address = reader.GetString(2);
                        }
                        listOfPos.Add(pos);
                    }
                    reader.Close();
                    result.Add(new OperatorPosList
                    {
                        Id       = item.Id,
                        Operator = item.Operator,
                        Caption  = item.Caption,
                        Poses    = listOfPos
                    });
                }
                #endregion

                response.PosLists  = result;
                response.ErrorCode = 0;
                response.Message   = string.Empty;
            }
            catch (Exception e)
            {
                response.ErrorCode = 3;
                response.Message   = e.Message;
            }
            finally
            {
                _cnn.Close();
            }
            return(response);
        }