コード例 #1
0
        private void saveChages(object depName)
        {
            Vedomost vedomost = new Vedomost();
            var      workshop = ApiConnector.getWorkshop((depName as string));

            if (workshop == null)
            {
                MessageBox.Show("Цех с таким названием не найден", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //List<Detail> details = (List<Detail>)ApiConnector.getDetails(); // Возможно, можно удалить эту строку

            vedomost.creation_date  = docCreateDate.Value.ToString("yyyy-MM-dd");
            vedomost.doc_num        = Convert.ToInt32(docNumberTextBox.Text);
            vedomost.workshop_pk    = workshop.workshop_pk;
            vedomost.vedomost_lines = new List <VedomostLine>();
            for (int i = 0; i < table.Rows.Count - 1; i++)
            {
                var vedomostLine = new VedomostLine();
                try
                {
                    vedomostLine.vedomost_line_pk = identificationTable[table.Rows[i]].vedomost_line_pk;
                    vedomostLine.vedomost_pk      = (Parent as EditingInventarization).vedomostLast.vedomost_pk;
                }
                catch { };
                vedomostLine.detail_pk = details.Find(detail => detail.detail_name == table.Rows[i].Cells[0].Value.ToString()).detail_pk;
                vedomostLine.amount    = Convert.ToInt32(table.Rows[i].Cells[2].Value);
                vedomost.vedomost_lines.Add(vedomostLine);
            }

            if (Parent is EditingInventarization)
            {
                vedomost.url         = (Parent as EditingInventarization).vedomostLast.url;
                vedomost.vedomost_pk = (Parent as EditingInventarization).vedomostLast.vedomost_pk;
                ApiConnector.editVedomost(vedomost);
                MessageBox.Show("Ведомость была успешно изменена.", "Редактирование ведомости", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                ApiConnector.createVedomost(vedomost);
                MessageBox.Show("Ведомость была успешно создана.", "Добавление ведомости", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            progressBar1.Visible = false;
            if (!(Parent is EditingInventarization))
            {
                table.Rows.Clear();
                depTextBox.Text       = "";
                docNumberTextBox.Text = "";
                docCreateDate.Value   = DateTime.Now;
            }
        }
コード例 #2
0
        public static void deleteVedomostLine(VedomostLine line)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(line.url);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "DELETE";

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
        }
コード例 #3
0
        public static void editVedomostLine(VedomostLine line)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(line.url);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "PUT";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = JsonConvert.SerializeObject(line);
                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
        }
コード例 #4
0
        public static void createVedomostLine(object param)
        {
            Tuple <Vedomost, VedomostLine> paramUnpacked = (Tuple <Vedomost, VedomostLine>)param;
            Vedomost     vedomost       = paramUnpacked.Item1;
            VedomostLine line           = paramUnpacked.Item2;
            var          httpWebRequest = (HttpWebRequest)WebRequest.Create("https://loloman.pythonanywhere.com/api/vedomost-lines/");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";
            line.vedomost_pk           = vedomost.vedomost_pk;

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = JsonConvert.SerializeObject(line);
                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
        }