コード例 #1
0
        private void btnAddItems_Click(object sender, EventArgs e)
        {
            if (cmb_brand.Items.Contains(cmb_brand.Text))
            {
                AddItem      selectID = new AddItem();
                string       BrandId  = selectID.select_id("vehicle_brand", "vehicle_brand_id", "brand_name", cmb_brand.Text.ToString());
                string       query    = "INSERT INTO `hashini_auto`.`vehicle_type` (`vehicle_brand_id`, `vehicle_name`) VALUES ('" + BrandId + "', '" + txtvehicle.Text + "')";
                MySqlCommand cmd      = new MySqlCommand(query, connection);
                connection.Open();

                cmd.ExecuteNonQuery();
                connection.Close();

                MessageBox.Show("Vehicle added succesfully");
            }
            else
            {
                string       iquery = "INSERT INTO `hashini_auto`.`vehicle_brand` (`brand_name`) VALUES ('" + cmb_brand.Text + "')";
                MySqlCommand cmd    = new MySqlCommand(iquery, connection);
                connection.Open();

                cmd.ExecuteNonQuery();
                connection.Close();
                AddItem      selectID = new AddItem();
                string       BrandId  = selectID.select_id("vehicle_brand", "vehicle_brand_id", "brand_name", cmb_brand.Text.ToString());
                string       query    = "INSERT INTO `hashini_auto`.`vehicle_type` (`vehicle_brand_id`, `vehicle_name`) VALUES ('" + BrandId + "', '" + txtvehicle.Text + "')";
                MySqlCommand ccmd     = new MySqlCommand(query, connection);
                connection.Open();

                ccmd.ExecuteNonQuery();
                connection.Close();
                txtvehicle.Text = "";
                MessageBox.Show("Vehicle added succesfully");
            }
        }
コード例 #2
0
ファイル: Search.cs プロジェクト: RangikaMark/TEST
        private void btn_search_Click(object sender, EventArgs e)
        {
            string  brand         = com_brand.SelectedItem.ToString();
            AddItem selectbrandID = new AddItem();

            brandID = selectbrandID.select_id("vehicle_brand", "vehicle_brand_id", "brand_name", brand);
            string  type            = com_vehicle_type.SelectedItem.ToString();
            AddItem selectVehicleId = new AddItem();

            vehicleID = selectVehicleId.select_id("vehicle_type", "vehicle_type_id", "vehicle_name", type);



            if (com_made_in.SelectedItem == null)
            {
                country_id = "";
            }
            else
            {
                string  madeIn    = com_made_in.SelectedItem.ToString();
                AddItem selectcId = new AddItem();
                country_id = selectcId.select_id("country", "country_id", "country_name", madeIn);
            }
            if (com_company.SelectedItem == null)
            {
                company = "";
            }
            else
            {
                string companyname = com_company.SelectedItem.ToString();

                AddItem selectId = new AddItem();
                company = selectId.select_id("items_brand", "items_brand_id", "items_brand_name", companyname);
            }



            for (int i = 0; i < part_type.Items.Count; i++)
            {
                if (part_type.GetItemChecked(i))
                {
                    string  strname  = (string)part_type.Items[i];
                    AddItem selectId = new AddItem();
                    string  partID   = selectId.select_id("part_type", "part_type_id", "part_type_name", strname);



                    if (company == "" && country_id == "")
                    {
                        query = " select  item_details.items_details_id,item_details.company_part_no ,part_type.part_type_name ,item_details.part_number,cost.cost,country.country_name from item_details inner join cost on cost.partNumber = item_details.part_number inner join part_type on item_details.part_type_id = part_type.part_type_id  inner join country on item_details.country_id = country.country_id inner join items_brand on items_brand.items_brand_id = item_details.items_brand_id where part_type.part_type_id ='" + partID + "' and " + vehicleID + " IN(vehicle_type_id_0, vehicle_type_id_1, vehicle_type_id_2, vehicle_type_id_3, vehicle_type_id_4, vehicle_type_id_5, vehicle_type_id_6, vehicle_type_id_7, vehicle_type_id_8, vehicle_type_id_9)";
                    }
                    else if (company == "")
                    {
                        query = " select item_details.items_details_id,item_details.company_part_no ,part_type.part_type_name ,item_details.part_number,cost.cost,country.country_name from item_details inner join cost on cost.partNumber = item_details.part_number inner join part_type on item_details.part_type_id = part_type.part_type_id  inner join country on item_details.country_id = country.country_id inner join items_brand on items_brand.items_brand_id = item_details.items_brand_id where part_type.part_type_id ='" + partID + "' and " + vehicleID + " IN(vehicle_type_id_0, vehicle_type_id_1, vehicle_type_id_2, vehicle_type_id_3, vehicle_type_id_4, vehicle_type_id_5, vehicle_type_id_6, vehicle_type_id_7, vehicle_type_id_8, vehicle_type_id_9) and country.country_id='" + country_id + "'";//    where part_type.part_type_name='" + str+"' and vehicle_brand.brand_name='nissan'";
                    }
                    else if (country_id == "")
                    {
                        query = " select item_details.items_details_id,item_details.company_part_no ,part_type.part_type_name ,item_details.part_number,cost.cost,country.country_name from item_details inner join cost on cost.partNumber = item_details.part_number inner join part_type on item_details.part_type_id = part_type.part_type_id  inner join country on item_details.country_id = country.country_id inner join items_brand on items_brand.items_brand_id = item_details.items_brand_id where part_type.part_type_id ='" + partID + "' and " + vehicleID + " IN(vehicle_type_id_0, vehicle_type_id_1, vehicle_type_id_2, vehicle_type_id_3, vehicle_type_id_4, vehicle_type_id_5, vehicle_type_id_6, vehicle_type_id_7, vehicle_type_id_8, vehicle_type_id_9) and items_brand.items_brand_id='" + company + "'"; //    where part_type.part_type_name='" + str+"' and vehicle_brand.brand_name='nissan'";
                    }
                    else
                    {
                        query = " select item_details.items_details_id,item_details.company_part_no ,part_type.part_type_name ,item_details.part_number,cost.cost,country.country_name from item_details inner join cost on cost.partNumber = item_details.part_number inner join part_type on item_details.part_type_id = part_type.part_type_id  inner join country on item_details.country_id = country.country_id inner join items_brand on items_brand.items_brand_id = item_details.items_brand_id where part_type.part_type_id ='" + partID + "' and " + vehicleID + " IN(vehicle_type_id_0, vehicle_type_id_1, vehicle_type_id_2, vehicle_type_id_3, vehicle_type_id_4, vehicle_type_id_5, vehicle_type_id_6, vehicle_type_id_7, vehicle_type_id_8, vehicle_type_id_9) and country.country_id='" + country_id + "' and items_brand.items_brand_id='" + company + "'"; //    where part_type.part_type_name='" + str+"' and vehicle_brand.brand_name='nissan'";
                    }
                    MySqlCommand command = new MySqlCommand(query, connection);
                    connection.Open();
                    MySqlDataReader mdr;

                    mdr = command.ExecuteReader();
                    while (mdr.Read())
                    {
                        item_id      = mdr.GetString("items_details_id");
                        partTypeName = mdr.GetString("part_type_name");
                        partNumber   = mdr.GetString("part_number");
                        countries    = mdr.GetString("country_name");
                        //  quantity = mdr.GetString("count(*)");
                        costPrice = mdr.GetString("cost");
                        //     vName = mdr.GetString("vehicle_name");
                        //    bName = mdr.GetString("brand_name");
                    }
                    mdr.Close();
                    connection.Close();
                    string          count = "select count(*) from item where items_detailId='" + item_id + "';";
                    MySqlCommand    cmd   = new MySqlCommand(count, connection);
                    MySqlDataReader cmdr;
                    connection.Open();
                    cmdr = cmd.ExecuteReader();
                    cmdr.Read();
                    quantity = cmdr.GetString("count(*)");
                    mdr.Close();
                    connection.Close();
                    this.searchGrid.Rows.Add(partNumber, partTypeName, countries, com_vehicle_type.Text, com_brand.Text, quantity, costPrice);


                    // MessageBox.Show(txt.ToString());
                }
            }
        }