private void btn_release_Click(object sender, EventArgs e)
        {
            int count = 0;

            for (int i = 0; i < this.dgv1.Rows.Count; i++)
            {
                if ((bool)dgv1.Rows[i].Cells[0].EditedFormattedValue == true)
                {
                    count++;
                }
            }
            if (count == 0)
            {
                MessageBox.Show("请至少选择一条数据。", "提示");
                return;
            }
            else
            {
                string site = string.Empty;
                for (int j = 0; j < this.dgv1.Rows.Count; j++)
                {
                    if ((bool)dgv1.Rows[j].Cells[0].EditedFormattedValue == true)
                    {
                        site = dgv1.Rows[j].Cells[2].Value.ToString();

                        string erp_partno   = dgv1.Rows[j].Cells[3].Value.ToString();
                        string erp_partname = dgv1.Rows[j].Cells[4].Value.ToString();
                        //partList.Add(site+","+ erp_partno + "," + erp_partname);
                        PartRelative pr = new PartRelative();
                        pr.CREATOR     = LogUser;
                        pr.ACTIVITYSEQ = Convert.ToInt32(Str_activity);
                        pr.ERP_PART_NO = erp_partno;
                        pr.PART_NAME   = erp_partname;
                        pr.PROJECTID   = Projectid;
                        pr.SITE        = site;
                        if (pr.IFmerged1())
                        {
                            pr.Delete();
                        }
                    }
                }
                MessageBox.Show("绑定关系解除成功");
            }
        }
        private void btn_commit_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                MessageBox.Show("请选择要合并的标准件编号", "Error");
                return;
            }
            if (cmb_parttype.Text.ToString() == string.Empty)
            {
                MessageBox.Show("请选择要合并的零件类型", "Error");
                return;
            }
            for (int i = 0; i < StrPartList.Count; i++)
            {
                string       strOne   = StrPartList[i].ToString();
                string       site     = strOne.Split(',')[0];
                string       partno   = strOne.Split(',')[1];
                string       partname = strOne.Split(',')[2];
                PartRelative pr       = new PartRelative();
                pr.CREATOR     = Username;
                pr.ACTIVITYSEQ = Convert.ToInt32(ActivitySeq);
                pr.ERP_PART_NO = partno;
                pr.PART_NAME   = partname;
                pr.PROJECTID   = ProjectId;
                pr.SITE        = site;
                pr.STA_PART_NO = textBox1.Text.ToString();
                if (partno == textBox1.Text.ToString())
                {
                    pr.STA_IF = "Y";
                }
                else
                {
                    pr.STA_IF = "N";
                }
                if (pr.IFmerged1())
                {
                    if (partno != textBox1.Text.ToString())
                    {
                        MessageBox.Show("零件" + partno + "已经被合并,请确认", "Error");
                        return;
                    }
                }
                pr.STA_PART_NO = partno;
                if (pr.IFStandardPart())
                {
                    if (partno != textBox1.Text.ToString())
                    {
                        MessageBox.Show("零件" + partno + "已经是标准件,不能被合并", "Error");
                        return;
                    }
                }
                pr.STA_PART_NO = textBox1.Text.ToString();
                if (!pr.FindExistRelative())
                {
                    pr.Add();
                }
            }
            StandartPart sp = new StandartPart();

            sp.PART_NAME   = txt_partname.Text.ToString();
            sp.PROJECTID   = ProjectId;
            sp.SITE        = txt_site.Text.ToString();
            sp.STA_PART_NO = textBox1.Text.ToString();
            sp.TYPEID      = Convert.ToInt32(cmb_parttype.SelectedValue.ToString());
            sp.CREATOR     = Username;
            if (!sp.FindExistStanPart())
            {
                sp.Add();
            }
            MessageBox.Show("合并成功");
            FindErpParts(textBox1.Text.ToString(), txt_site.Text.ToString());
        }
        public void listviewBind(string sql)
        {
            this.dgv1.AutoGenerateColumns = false;
            this.dgv1.Rows.Clear();
            DataSet  ds = MEOsub.QueryPartMiscProcListEPR(sql);
            DataView dv = ds.Tables[0].DefaultView;
            int      i  = 1;

            foreach (DataRow dr in dv.Table.Rows)
            {
                string        projectid = dr[1].ToString();
                string        partno    = dr[2].ToString();
                string        site      = dr[0].ToString();
                PartParameter pp        = PartParameter.Find(0, projectid, partno, site, "weijun.qu");
                decimal       preQty    = 0;
                decimal       singleW   = 0;
                decimal       preAlert  = 0;
                if (pp != null)
                {
                    preQty   = pp.PREDICTION_QTY;
                    singleW  = pp.WEIGHT_SINGLE;
                    preAlert = pp.PREDICTION_ALERT;
                }
                PartRelative pr = new PartRelative();
                pr.ERP_PART_NO = partno;
                pr.STA_PART_NO = partno;
                pr.SITE        = site;
                pr.PROJECTID   = projectid;
                pr.ACTIVITYSEQ = Convert.ToInt32(Str_activity);
                string isStandPart = "";
                string isMerged    = "";
                if (pr.IFStandardPart())
                {
                    isStandPart = "是";
                }
                if (pr.IFmerged1())
                {
                    isMerged = "是";
                }
                string          StnPartno = PartRelative.FindRelativeStnPartno(partno, projectid, Convert.ToInt32(Str_activity), site);
                DataGridViewRow r         = new DataGridViewRow();
                r.CreateCells(dgv1);
                r.Cells[1].Value             = i.ToString();
                r.Cells[2].Value             = dr[0].ToString();
                r.Cells[3].Value             = dr[2].ToString();
                r.Cells[4].Value             = dr[3].ToString();
                r.Cells[5].Value             = dr[4].ToString();
                dgv1.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                r.Cells[6].Value             = pp == null ? string.Empty : pp.PREDICTION_QTY.ToString();
                r.Cells[7].Value             = pp == null ? string.Empty : pp.WEIGHT_SINGLE.ToString();
                r.Cells[8].Value             = isMerged;
                r.Cells[9].Value             = isStandPart;
                r.Cells[10].Value            = StnPartno;
                //r.Cells[8].Value = MeoNo;
                //r.Cells[9].Value = MeoQty.ToString();
                //r.Cells[10].Value = Str_MeoPcs;

                //r.Cells[11].Value = Str_Meotime;
                //r.Cells[12].Value = restQty.ToString();
                //r.Cells[13].Value = MssQty.ToString();

                this.dgv1.Rows.Add(r);
                i++;
            }
        }
        private void btn_copy_Click(object sender, EventArgs e)
        {
            if (groupBox3.Visible == false)
            {
                groupBox3.Visible = true;
            }
            if (cmb_parttype.Text == string.Empty)
            {
                MessageBox.Show("请选择材料种类。", "提示");
                return;
            }
            int count = 0;

            for (int i = 0; i < this.dgv1.Rows.Count; i++)
            {
                if ((bool)dgv1.Rows[i].Cells[0].EditedFormattedValue == true)
                {
                    count++;
                }
            }
            if (count == 0)
            {
                MessageBox.Show("请至少选择一条数据。", "提示");
                return;
            }
            else
            {
                ArrayList partList = new ArrayList();
                string    site     = string.Empty;
                for (int j = 0; j < this.dgv1.Rows.Count; j++)
                {
                    if ((bool)dgv1.Rows[j].Cells[0].EditedFormattedValue == true)
                    {
                        site = dgv1.Rows[j].Cells[2].Value.ToString();

                        string erp_partno   = dgv1.Rows[j].Cells[3].Value.ToString();
                        string erp_partname = dgv1.Rows[j].Cells[4].Value.ToString();
                        //partList.Add(site+","+ erp_partno + "," + erp_partname);
                        PartRelative pr = new PartRelative();
                        pr.CREATOR     = LogUser;
                        pr.ACTIVITYSEQ = Convert.ToInt32(Str_activity);
                        pr.ERP_PART_NO = erp_partno;
                        pr.PART_NAME   = erp_partname;
                        pr.PROJECTID   = Projectid;
                        pr.SITE        = site;
                        pr.STA_PART_NO = erp_partno;
                        pr.STA_IF      = "Y";

                        if (pr.IFmerged1())
                        {
                            MessageBox.Show("零件" + erp_partno + "已经被合并,请确认", "Error");
                            return;
                        }
                        pr.STA_PART_NO = erp_partno;
                        if (pr.IFStandardPart())
                        {
                            MessageBox.Show("零件" + erp_partno + "已经是标准件,不能被合并", "Error");
                            return;
                        }
                        pr.STA_PART_NO = erp_partno;
                        if (!pr.FindExistRelative())
                        {
                            pr.Add();
                        }
                        StandartPart sp = new StandartPart();
                        sp.PART_NAME   = erp_partname;
                        sp.PROJECTID   = Projectid;
                        sp.SITE        = site;
                        sp.STA_PART_NO = erp_partno;
                        sp.TYPEID      = Convert.ToInt32(cmb_parttype.SelectedValue.ToString());
                        sp.CREATOR     = LogUser;
                        if (!sp.FindExistStanPart())
                        {
                            sp.Add();
                        }
                    }

                    // FindErpParts(textBox1.Text.ToString(), txt_site.Text.ToString());
                }
                MessageBox.Show("选中零件已经成功复制到标准零件库");
            }
        }