Пример #1
0
        private void ly_production_orderDataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (null == this.ly_production_orderDataGridView.CurrentRow)
            {
                return;
            }

            DataGridView dgv      = sender as DataGridView;
            string       taskCode = this.ly_production_orderDataGridView.CurrentRow.Cells["任务单号"].Value.ToString();


            using (SqlConnection con = new SqlConnection(SQLDatabase.Connectstring))
            {
                string sql = "select COUNT(1) from  ly_store_out where  pruductionTaskInspection_num='" + taskCode + "'";
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    con.Open();
                    int k = Convert.ToInt32(cmd.ExecuteScalar());
                    if (k > 0)
                    {
                        MessageBox.Show("已有出入库记录不可删除", "注意");
                        return;
                    }
                }
            }

            using (SqlConnection con = new SqlConnection(SQLDatabase.Connectstring))
            {
                string sql = "select COUNT(1) from  ly_store_in where  pruductionTaskInspection_num='" + taskCode + "'";
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    con.Open();
                    int k = Convert.ToInt32(cmd.ExecuteScalar());
                    if (k > 0)
                    {
                        MessageBox.Show("已有出入库记录不可删除", "注意");
                        return;
                    }
                }
            }

            if ("加工数量" == dgv.CurrentCell.OwningColumn.Name)
            {
                ChangeValue queryForm = new ChangeValue();

                queryForm.OldValue   = dgv.CurrentCell.Value.ToString();
                queryForm.NewValue   = "";
                queryForm.ChangeMode = "value";
                queryForm.ShowDialog();



                if (queryForm.NewValue != "")
                {
                    dgv.CurrentRow.Cells["加工数量"].Value = queryForm.NewValue;

                    int noworderValue = 0;

                    int nowplanValue = int.Parse(this.ly_material_plan_detailDataGridView.CurrentRow.Cells["数量"].Value.ToString(), System.Globalization.NumberStyles.Number);


                    foreach (DataGridViewRow dgr in dgv.Rows)
                    {
                        if (string.IsNullOrEmpty(dgr.Cells["加工数量"].Value.ToString()))
                        {
                            continue;
                        }
                        noworderValue = noworderValue + int.Parse(dgr.Cells["加工数量"].Value.ToString(), System.Globalization.NumberStyles.Number);
                    }

                    if (noworderValue > nowplanValue)
                    {
                        dgv.CurrentRow.Cells["加工数量"].Value = queryForm.OldValue;
                        MessageBox.Show("任务安排不能超过计划数量,操作取消...", "注意");
                        return;
                    }


                    dgv.CurrentRow.Cells["加工数量"].Value = queryForm.NewValue;
                    //dgv.CurrentRow.Cells["discount_money"].Value = DBNull.Value;

                    //dgv.CurrentRow.Cells["approve_flag"].Value = "False";
                    SaveChanged();


                    //CountPlanStru();
                }
                else
                {
                    //hT_Manage_ItemDataGridView.CurrentRow.Cells["apply_money"].Value = queryForm.NewValue;
                    //dgv.CurrentRow.Cells["discount_money"].Value = DBNull.Value;
                    //dgv.CurrentRow.Cells["apply_money"].Value = DBNull.Value;
                    //dgv.CurrentRow.Cells["approve_flag"].Value = "False";
                    //SaveChanged();
                }
                return;
            }
            ///////////////////////////////////////////////////////

            if ("工号" == dgv.CurrentCell.OwningColumn.Name || "工人" == dgv.CurrentCell.OwningColumn.Name)
            {
                //if (!checkqualityRec() && "系统管理员" != SQLDatabase.nowUserName())
                //{

                //    MessageBox.Show("任务已有检验记录,不能修改, 操作取消", "注意");

                //    return;

                //}

                //string outflag = this.ly_production_order_detailDataGridView.CurrentRow.Cells["外协"].Value.ToString();
                string sel;

                //if ("True" == outflag)
                //{

                //    sel = "SELECT  supplier_code as 工号, supplier_name as 姓名 FROM ly_supplier_list where sort_code='4'";
                //}
                //else
                //{

                //    sel = "SELECT  work_code as 工号, worker_name as 姓名 FROM ly_worker_list";
                //}

                sel = "SELECT  work_code as 工号, worker_name as 姓名 FROM ly_worker_list where prodcode='02'";
                QueryForm queryForm = new QueryForm();


                queryForm.Sel    = sel;
                queryForm.Constr = SQLDatabase.Connectstring;

                //Set the Column Collection to the filter Table
                //queryForm.SetSourceColumns(this.billMainDataSet.BalanceBill.Columns);

                queryForm.ShowDialog();


                if (queryForm.Result != "")
                {
                    dgv.CurrentRow.Cells["工号"].Value = queryForm.Result;
                    dgv.CurrentRow.Cells["工人"].Value = queryForm.Result1;
                    //dgv.CurrentRow.Cells["discount_money"].Value = DBNull.Value;

                    //dgv.CurrentRow.Cells["approve_flag"].Value = "False";
                    SaveChanged();


                    //CountPlanStru();
                }
                else
                {
                    dgv.CurrentRow.Cells["工号"].Value = DBNull.Value;
                    dgv.CurrentRow.Cells["工人"].Value = DBNull.Value;
                    //dgv.CurrentRow.Cells["discount_money"].Value = DBNull.Value;

                    //dgv.CurrentRow.Cells["approve_flag"].Value = "False";
                    SaveChanged();
                }
                return;
            }


            ///////////////////////////////////////////////////////


            ///////////////////////////////////////////////////////

            if ("下单日期" == dgv.CurrentCell.OwningColumn.Name)
            {
                DatePicker queryForm = new DatePicker();
                queryForm.Pt = pt;

                if (null != (dgv.CurrentCell.Value))
                {
                    queryForm.NowDate = dgv.CurrentCell.Value.ToString();
                }

                queryForm.ShowDialog();



                if (null != queryForm.NowDate)
                {
                    dgv.CurrentRow.Cells["下单日期"].Value = queryForm.NowDate;
                    SaveChanged();
                }
                return;
            }


            ///////////////////////////////////////////////////////

            if ("完成日期" == dgv.CurrentCell.OwningColumn.Name)
            {
                DatePicker queryForm = new DatePicker();
                queryForm.Pt = pt;

                if (null != (dgv.CurrentCell.Value))
                {
                    queryForm.NowDate = dgv.CurrentCell.Value.ToString();
                }
                else
                {
                    queryForm.NowDate = SQLDatabase.GetNowdate().Date.ToString();
                }

                queryForm.ShowDialog();



                if (null != queryForm.NowDate)
                {
                    dgv.CurrentRow.Cells["完成日期"].Value = queryForm.NowDate;
                    SaveChanged();
                }
                return;
            }



            ///////////////////////////////////////////////////////

            if ("备注" == dgv.CurrentCell.OwningColumn.Name)
            {
                ChangeValue queryForm = new ChangeValue();

                queryForm.OldValue = dgv.CurrentCell.Value.ToString();
                queryForm.NewValue = "";
                //queryForm.ChangeMode = "value";
                queryForm.ShowDialog();



                if (queryForm.NewValue != "")
                {
                    dgv.CurrentRow.Cells["备注"].Value = queryForm.NewValue;
                    //dgv.CurrentRow.Cells["discount_money"].Value = DBNull.Value;

                    //dgv.CurrentRow.Cells["approve_flag"].Value = "False";
                    SaveChanged();


                    //CountPlanStru();
                }
                else
                {
                }
                return;
            }

            /////////////////////////////

            if ("完成" == dgv.CurrentCell.OwningColumn.Name)
            {
                if (!SQLDatabase.CheckHaveRight(SQLDatabase.NowUserID, "跟单完成设置"))
                {
                    MessageBox.Show("无跟单完成设置权限,操作取消...", "注意");
                    return;
                }

                if ("True" == dgv.CurrentRow.Cells["完成"].Value.ToString())
                {
                    dgv.CurrentRow.Cells["完成"].Value = "False";
                }
                else
                {
                    dgv.CurrentRow.Cells["完成"].Value = "True";
                }



                SaveChanged();



                return;
            }


            ///////////////////////////////////////////////////////
        }
        private void ly_production_orderDataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (null == this.ly_production_orderDataGridView.CurrentRow)
            {
                return;
            }

            DataGridView dgv        = sender as DataGridView;
            string       taskMumber = ly_production_orderDataGridView.CurrentRow.Cells["任务单号"].Value.ToString();



            using (SqlConnection con = new SqlConnection(SQLDatabase.Connectstring))
            {
                string sql = "select COUNT(1) from  ly_store_out where  pruductionTaskInspection_num='" + taskMumber + "'";
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    con.Open();
                    int k = Convert.ToInt32(cmd.ExecuteScalar());
                    if (k > 0)
                    {
                        MessageBox.Show("已有出入库记录不可删除", "注意");
                        return;
                    }
                }
            }

            using (SqlConnection con = new SqlConnection(SQLDatabase.Connectstring))
            {
                string sql = "select COUNT(1) from  ly_store_in where  pruductionTaskInspection_num='" + taskMumber + "'";
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    con.Open();
                    int k = Convert.ToInt32(cmd.ExecuteScalar());
                    if (k > 0)
                    {
                        MessageBox.Show("已有出入库记录不可删除", "注意");
                        return;
                    }
                }
            }



            if (ly_restructuring_task_inspectionDataGridView.Rows.Count > 0)
            {
                foreach (DataGridViewRow dgr in ly_restructuring_task_inspectionDataGridView.Rows)
                {
                    if ("True" == dgr.Cells["合格"].Value.ToString())
                    {
                        MessageBox.Show("已经质检合格,不能删除(实需删除,请先清除质检合格标记)", "注意");
                        return;
                    }
                    if ("True" == dgr.Cells["出库"].Value.ToString())
                    {
                        MessageBox.Show("已经领料,不能删除(实需删除,请先清除领料标记)", "注意");
                        return;
                    }

                    if ("True" == dgr.Cells["入库"].Value.ToString())
                    {
                        MessageBox.Show("已经入库,不能删除(实需删除,请先删除该质检单号的入库记录)", "注意");
                        return;
                    }
                }
            }


            if ("加工数量" == dgv.CurrentCell.OwningColumn.Name)
            {
                ChangeValue queryForm = new ChangeValue();

                queryForm.OldValue   = dgv.CurrentCell.Value.ToString();
                queryForm.NewValue   = "";
                queryForm.ChangeMode = "value";
                queryForm.ShowDialog();
                if (queryForm.NewValue != "")
                {
                    dgv.CurrentRow.Cells["加工数量"].Value = queryForm.NewValue;

                    int noworderValue = 0;

                    int nowplanValue = int.Parse(this.ly_material_plan_detailDataGridView.CurrentRow.Cells["改制数量"].Value.ToString(), System.Globalization.NumberStyles.Number);


                    foreach (DataGridViewRow dgr in dgv.Rows)
                    {
                        if (string.IsNullOrEmpty(dgr.Cells["加工数量"].Value.ToString()))
                        {
                            continue;
                        }
                        noworderValue = noworderValue + int.Parse(dgr.Cells["加工数量"].Value.ToString(), System.Globalization.NumberStyles.Number);
                    }

                    if (noworderValue > nowplanValue)
                    {
                        dgv.CurrentRow.Cells["加工数量"].Value = queryForm.OldValue;
                        MessageBox.Show("任务安排不能超过计划数量,操作取消...", "注意");
                        return;
                    }
                    dgv.CurrentRow.Cells["加工数量"].Value = queryForm.NewValue;
                    dgv.CurrentRow.Cells["未入库数"].Value = queryForm.NewValue;
                    InsertRequset(dgv);
                    SaveChanged(int.Parse(dgv.CurrentRow.Cells["改制编号"].Value.ToString()));
                }
                else
                {
                }
                return;
            }

            if ("工号" == dgv.CurrentCell.OwningColumn.Name || "工人" == dgv.CurrentCell.OwningColumn.Name)
            {
                string sel;


                sel = "SELECT  work_code as 工号, worker_name as 姓名 FROM ly_worker_list where prodcode='02'";
                QueryForm queryForm = new QueryForm();


                queryForm.Sel    = sel;
                queryForm.Constr = SQLDatabase.Connectstring;

                queryForm.ShowDialog();


                if (queryForm.Result != "")
                {
                    dgv.CurrentRow.Cells["工号"].Value = queryForm.Result;
                    dgv.CurrentRow.Cells["工人"].Value = queryForm.Result1;

                    InsertRequset(dgv);

                    SaveChanged(int.Parse(dgv.CurrentRow.Cells["改制编号"].Value.ToString()));
                }
                else
                {
                    dgv.CurrentRow.Cells["工号"].Value = DBNull.Value;
                    dgv.CurrentRow.Cells["工人"].Value = DBNull.Value;

                    SaveChanged(int.Parse(dgv.CurrentRow.Cells["改制编号"].Value.ToString()));
                }
                return;
            }


            if ("下单日期" == dgv.CurrentCell.OwningColumn.Name)
            {
                DatePicker queryForm = new DatePicker();
                queryForm.Pt = pt;

                if (null != (dgv.CurrentCell.Value))
                {
                    queryForm.NowDate = dgv.CurrentCell.Value.ToString();
                }

                queryForm.ShowDialog();



                if (null != queryForm.NowDate)
                {
                    dgv.CurrentRow.Cells["下单日期"].Value = queryForm.NowDate;
                    SaveChanged(int.Parse(dgv.CurrentRow.Cells["改制编号"].Value.ToString()));
                }
                return;
            }


            if ("完成日期" == dgv.CurrentCell.OwningColumn.Name)
            {
                DatePicker queryForm = new DatePicker();
                queryForm.Pt = pt;

                if (null != (dgv.CurrentCell.Value))
                {
                    queryForm.NowDate = dgv.CurrentCell.Value.ToString();
                }
                else
                {
                    queryForm.NowDate = SQLDatabase.GetNowdate().Date.ToString();
                }

                queryForm.ShowDialog();



                if (null != queryForm.NowDate)
                {
                    dgv.CurrentRow.Cells["完成日期"].Value = queryForm.NowDate;
                    SaveChanged(int.Parse(dgv.CurrentRow.Cells["改制编号"].Value.ToString()));
                }
                return;
            }



            if ("任务单备注" == dgv.CurrentCell.OwningColumn.Name)
            {
                ChangeValue queryForm = new ChangeValue();

                queryForm.OldValue = dgv.CurrentCell.Value.ToString();
                queryForm.NewValue = "";

                queryForm.ShowDialog();
                if (queryForm.NewValue != "")
                {
                    dgv.CurrentRow.Cells["任务单备注"].Value = queryForm.NewValue;
                    SaveChanged(int.Parse(dgv.CurrentRow.Cells["改制编号"].Value.ToString()));
                }
                else
                {
                }
                return;
            }


            if ("完成" == dgv.CurrentCell.OwningColumn.Name)
            {
                if (!SQLDatabase.CheckHaveRight(SQLDatabase.NowUserID, "跟单完成设置"))
                {
                    MessageBox.Show("无跟单完成设置权限,操作取消...", "注意");
                    return;
                }

                if ("True" == dgv.CurrentRow.Cells["完成"].Value.ToString())
                {
                    dgv.CurrentRow.Cells["完成"].Value = "False";
                }
                else
                {
                    dgv.CurrentRow.Cells["完成"].Value = "True";
                }

                SaveChanged(int.Parse(dgv.CurrentRow.Cells["改制编号"].Value.ToString()));
                return;
            }
        }