public InjectionMaterial getByID(string _id)
        {
            InjectionMaterial injectionMaterial = null;
            try
            {
                conn = db.openConn();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append(" SELECT id,name FROM injection_materials ");
                sb.Append(" WHERE id='" + _id + "'");

                string sql;
                sql = sb.ToString();
                comm = new SqlCommand();
                comm.CommandText = sql;
                comm.CommandType = CommandType.Text;
                comm.Connection = conn;
                dr = comm.ExecuteReader();
                if (dr.HasRows)
                {

                    DataTable dt = new DataTable();
                    dt.Load(dr);
                    foreach (DataRow drw in dt.Rows)
                    {
                        injectionMaterial = new InjectionMaterial();
                        injectionMaterial.ID = Convert.ToInt32(drw["id"].ToString());
                        injectionMaterial.Name = drw["name"].ToString();

                    }
                }

            }
            catch (Exception ex)
            {
                dr.Close();
                conn.Close();
                return null;
                throw ex;

            }
            finally
            {
                conn.Close();
            }

            return injectionMaterial;
        }
        private void cbomachine_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cbomachine.Items.Count >0) {
                injectionMachine = machineService.getByID(cbomachine.SelectedValue.ToString());
                if (injectionMachine != null)
                {
                    lblmachine.Text = injectionMachine.MoldNo;
                    lblsharp.Text ="#";

                    //rev
                    List<InjectionCabinetNumber> injectionCabinetNumbers = injectionService.getInjectionAll(cbopart.Text.Trim(), cboComplete.Text.Trim(), cbomachine.SelectedValue.ToString());
                    if (injectionCabinetNumbers != null && injectionCabinetNumbers.Count > 0)
                    {
                        lblrevision.Text = injectionCabinetNumbers[0].Rev;
                    }
                    else {
                        lblrevision.Text = "";
                    }

                    // color
                    List<InjectionCabinetNumber> injectionCabinetNumbers2 = injectionService.getInjectionAll(cbopart.Text.Trim(), cboComplete.Text.Trim(), cbomachine.SelectedValue.ToString());
                    if (injectionCabinetNumbers != null && injectionCabinetNumbers.Count > 0) {
                        injectionColors = colorservice.getByID(injectionCabinetNumbers2[0].ColorID);
                        if (injectionColors != null )
                        {
                            lbocolor.Text = injectionColors.Name;
                        }
                        else {
                            lbocolor.Text = "";
                        }

                        // meterial
                        injectionMaterial = meterialService.getByID(injectionCabinetNumbers2[0].MeterailID);
                        if (injectionMaterial != null)
                        {
                            lblmeterial.Text = injectionMaterial.Name;
                        }
                        else
                        {
                            lblmeterial.Text = "";
                        }

                    }

                }
                else {
                    lblmachine.Text = "";
                    lblsharp.Text = "";
                }

            }
        }