public List<InjectionPanalNumber> getInjectionAllByPart(string _part, string _completeno,string _machinno)
        {
            List<InjectionPanalNumber> injectionPanalNumbers = new List<InjectionPanalNumber>();
            InjectionPanalNumber inc;
            try
            {
                conn = db.openConn();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append(" SELECT id,part,complete_no,rev,material_no,color_no,machine_no,user_create_name,create_date,status FROM injection_panal_numbers ");
                sb.Append(" WHERE part='" + _part + "'");
                sb.Append(" and complete_no='" + _completeno + "'");
                sb.Append(" and machine_no='" + _machinno + "'");

                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)
                    {
                        inc = new InjectionPanalNumber();
                        inc.ID = Convert.ToInt32(drw["id"].ToString());
                        inc.Part = drw["part"].ToString();
                        inc.CompleteNo = drw["complete_no"].ToString();
                        inc.Rev = drw["rev"].ToString();

                        InjectionMaterial injectionMaterial = meterialService.getByID(Convert.ToString(drw["material_no"].ToString()));
                        inc.MeterailID = Convert.ToString(injectionMaterial.ID);
                        inc.MeterialName = injectionMaterial.Name;

                        InjectionColor injectionColor = colorService.getByID(Convert.ToString(drw["color_no"].ToString()));
                        inc.ColorID = Convert.ToString(injectionColor.ID);
                        inc.ColorName = injectionColor.Name;

                        InjectionMachine injectionMachine = machineService.getByID(Convert.ToString(drw["machine_no"].ToString()));
                        inc.MechineID = Convert.ToString(injectionMachine.ID);
                        inc.MechineName = injectionMachine.Name;
                        inc.MoldNo = injectionMachine.MoldNo;

                        inc.UserCreateName = drw["user_create_name"].ToString();
                        inc.CreateDate = Convert.ToDateTime(drw["create_date"].ToString());
                        inc.Status = drw["status"].ToString();
                        injectionPanalNumbers.Add(inc);
                    }
                }

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

            }
            finally
            {
                conn.Close();
            }
            return injectionPanalNumbers;
        }
        public int UpdateInjectionPanalNumber(InjectionPanalNumber _injectionPanalNumber)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();

                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append(" UPDATE injection_panal_numbers ");
                sb.Append(" SET rev='" + _injectionPanalNumber.Rev + "',");
                sb.Append(" material_no='" + _injectionPanalNumber.MechineID + "',");
                sb.Append(" color_no='" + _injectionPanalNumber.ColorID + "',");
                sb.Append(" machine_no='" + _injectionPanalNumber.MechineID + "'");
                sb.Append(" WHERE (complete_no='" + _injectionPanalNumber.CompleteNo + "')");
                sb.Append(" and (part='" + _injectionPanalNumber.Part + "')");
                string sqlUpdate;
                sqlUpdate = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = sqlUpdate;
                comm.Transaction = tr;
                comm.Parameters.Clear();
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }

            return result;
        }
        public int CreateInjectionPanalNumber(InjectionPanalNumber newInjectionPanalNumber)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO injection_panal_numbers(part,complete_no,rev,material_no,color_no,machine_no,user_create_name,create_date,status)");
                sb.Append(" VALUES (@part,@complete_no,@rev,@material_no,@color_no,@machine_no,@user_create_name,@create_date,@status)");

                string sqlsave;
                sqlsave = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.Transaction = tr;
                comm.CommandText = sqlsave;
                comm.Parameters.Clear();
                comm.Parameters.Add("@part", SqlDbType.NVarChar).Value = newInjectionPanalNumber.Part;
                comm.Parameters.Add("@complete_no", SqlDbType.NVarChar).Value = newInjectionPanalNumber.CompleteNo;
                comm.Parameters.Add("@rev", SqlDbType.NVarChar).Value = newInjectionPanalNumber.Rev;
                comm.Parameters.Add("@material_no", SqlDbType.NVarChar).Value = newInjectionPanalNumber.MeterailID;
                comm.Parameters.Add("@color_no", SqlDbType.NVarChar).Value = newInjectionPanalNumber.ColorID;
                comm.Parameters.Add("@machine_no", SqlDbType.NVarChar).Value = newInjectionPanalNumber.MechineID;
                comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newInjectionPanalNumber.UserCreateName;
                comm.Parameters.Add("@create_date", SqlDbType.DateTime).Value = newInjectionPanalNumber.CreateDate;
                comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newInjectionPanalNumber.Status;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }
            return result;
        }