Ejemplo n.º 1
0
        private void btnMPS_Click(object sender, EventArgs e)
        {
            String table_name = "МПС";

            string        connectionString = null;
            SqlConnection conn;

            connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Transport;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            conn             = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = "CREATE TABLE [dbo].МПС ([ИД] INT IDENTITY (1, 1) NOT NULL, [Вид] NCHAR (30), [Рег_номер] NVARCHAR (10), [Марка] NVARCHAR (30), [Модел] NVARCHAR (20), [Нето] REAL, [Товароподемност] REAL, [ВИН_номер] NCHAR (17), [ДВГ_номер] NCHAR (20), [Оси] INT, [Вместимост_резервоар] REAL, PRIMARY KEY CLUSTERED ([Рег_номер] ASC))";

            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                //MessageBox.Show("Таблицата " + table_name + " вече е създадена!");
                conn.Close();
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Има съществуваща таблица.");
            }

            MPS mps = new MPS();

            mps.Show();
        }
Ejemplo n.º 2
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            int    nomer_paten_list, nomer_tovaritelnitsa;
            string dateString;
            String MPS, full_name, objekt_begin, object_end;

            String[] material       = new String[4];
            String[] merna_edinitsa = new String[4];
            nomer_paten_list     = 0;
            nomer_tovaritelnitsa = 0;
            dateString           = null;
            MPS               = null;
            full_name         = null;
            objekt_begin      = null;
            object_end        = null;
            material[0]       = null;
            material[1]       = null;
            material[2]       = null;
            material[3]       = null;
            merna_edinitsa[0] = null;
            merna_edinitsa[1] = null;
            merna_edinitsa[2] = null;
            merna_edinitsa[3] = null;
            CultureInfo culture = new CultureInfo("bg-BG");

            string        connectionString = null;
            SqlConnection conn;

            connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Transport;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            conn             = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection       = conn;
            cmd.CommandText      = "SELECT ИД, Дата, МПС, Начало_км, Край_км, Км_товарителница, Отработени_часове, Шофьор, Номер_пътен_лист, Номер_товарителница, Обект_начало, Обект_край, Материал_1, Материал_2, Материал_3, Материал_4, Количество_текст_1, Количество_текст_2, Количество_текст_3, Количество_текст_4, Мерна_единица_1, Мерна_единица_2, Мерна_единица_3, Мерна_единица_4, Км, Гориво FROM Отчет WHERE (Номер_пътен_лист=@Number_paten_list AND Номер_товарителница=@Number_tovaritelnitsa)";
            nomer_paten_list     = int.Parse(txtNumber_p_list.Text);
            nomer_tovaritelnitsa = int.Parse(txtNumber_tovar.Text);
            cmd.Parameters.AddWithValue("@Number_paten_list", nomer_paten_list);
            cmd.Parameters.AddWithValue("@Number_tovaritelnitsa", nomer_tovaritelnitsa);
            dateString                       = dtpDateFrom.Value.ToShortDateString();
            cmbMPS.SelectedIndex             = -1;
            cmbDriver.SelectedIndex          = -1;
            cmbMerna_edinitsa1.SelectedIndex = -1;
            cmbMerna_edinitsa2.SelectedIndex = -1;
            cmbMerna_edinitsa3.SelectedIndex = -1;
            cmbMerna_edinitsa4.SelectedIndex = -1;
            if (nomer_paten_list != 0 && nomer_tovaritelnitsa != 0)
            {
                conn.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                sdr.Read();
                dtpDateFrom.CustomFormat = "dd-MM-yyyy";
                dtpDateFrom.Value        = Convert.ToDateTime(sdr["Дата"].ToString());
                MPS = sdr["МПС"].ToString();
                MPS = MPS.Trim();
                cmbMPS.SelectedText      = MPS;
                txtBegin.Text            = sdr["Начало_км"].ToString();
                txtEnd.Text              = sdr["Край_км"].ToString();
                txtKmTovaritelnitsa.Text = sdr["Км_товарителница"].ToString();
                txtHoursWorked.Text      = sdr["Отработени_часове"].ToString();
                full_name = sdr["Шофьор"].ToString();
                full_name = full_name.Trim();
                cmbDriver.SelectedText      = full_name;
                txtNumber_p_list.Text       = sdr["Номер_пътен_лист"].ToString();
                txtNumber_tovar.Text        = sdr["Номер_товарителница"].ToString();
                objekt_begin                = sdr["Обект_начало"].ToString();
                objekt_begin                = objekt_begin.Trim();
                cmbObjectBegin.SelectedText = objekt_begin;
                object_end = sdr["Обект_край"].ToString();
                object_end = object_end.Trim();
                cmbObjectEnd.SelectedText = object_end;
                material[0] = sdr["Материал_1"].ToString();
                material[0] = material[0].Trim();
                cmbMaterial1.SelectedText = material[0];
                material[1] = sdr["Материал_2"].ToString();
                material[1] = material[1].Trim();
                cmbMaterial2.SelectedText = material[1];
                material[2] = sdr["Материал_3"].ToString();
                material[2] = material[2].Trim();
                cmbMaterial3.SelectedText = material[2];
                material[3] = sdr["Материал_4"].ToString();
                material[3] = material[3].Trim();
                cmbMaterial4.SelectedText       = material[3];
                txtKolichestvo1.Text            = sdr["Количество_текст_1"].ToString();
                txtKolichestvo2.Text            = sdr["Количество_текст_2"].ToString();
                txtKolichestvo3.Text            = sdr["Количество_текст_3"].ToString();
                txtKolichestvo4.Text            = sdr["Количество_текст_4"].ToString();
                merna_edinitsa[0]               = sdr["Мерна_единица_1"].ToString();
                merna_edinitsa[0]               = merna_edinitsa[0].Trim();
                cmbMerna_edinitsa1.SelectedText = merna_edinitsa[0];
                merna_edinitsa[1]               = sdr["Мерна_единица_2"].ToString();
                merna_edinitsa[1]               = merna_edinitsa[1].Trim();
                cmbMerna_edinitsa2.SelectedText = merna_edinitsa[1];
                merna_edinitsa[2]               = sdr["Мерна_единица_3"].ToString();
                merna_edinitsa[2]               = merna_edinitsa[2].Trim();
                cmbMerna_edinitsa3.SelectedText = merna_edinitsa[2];
                merna_edinitsa[3]               = sdr["Мерна_единица_4"].ToString();
                merna_edinitsa[3]               = merna_edinitsa[3].Trim();
                cmbMerna_edinitsa4.SelectedText = merna_edinitsa[3];
                txtGorivo.Text = sdr["Гориво"].ToString();
                conn.Close();
            }
        }