public bool RecordingUpdate(PlanningBLL u)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                String sql = @"UPDATE tbl_plan SET
                                recording=@recording
                                WHERE plan_id=@plan_id";

                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@plan_id", u.plan_id);
                cmd.Parameters.AddWithValue("@recording", u.recording);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                //if the query is executed successfully then the rows' value = 0
                if (rows > 0)
                {
                    //query successful
                    isSuccess = true;
                }
                else
                {
                    //Query falled
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                Module.Tool tool = new Module.Tool(); tool.saveToText(ex);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
예제 #2
0
        private void Summary(PlanningBLL u)
        {
            lblPartName.Text      = u.part_name;
            lblPartCode.Text      = u.part_code;
            lblQuoTon.Text        = u.quo_ton;
            lblCycleTime.Text     = u.plan_ct + " SEC";
            lblProductionFor.Text = u.production_purpose;

            lblMaterial.Text   = u.material_code;
            lblBagQty.Text     = u.material_bag_qty + " x " + u.material_bag_kg + " KG";
            lblRecycleUse.Text = u.material_recycle_use + " KG";

            lblColor.Text         = u.part_color;
            lblColorMaterial.Text = u.color_material_code;
            lblUsage.Text         = u.color_material_usage + " %";
            lblColorMatQty.Text   = u.color_material_qty + " KG";

            lblTargetQty.Text     = u.production_target_qty;
            lblAbleToProduce.Text = u.production_able_produce_qty;
            lblProductionDay.Text = u.production_day + " DAY(" + u.production_hour_per_day + ") + " + u.production_hour + " HRS";
        }
        //production plan add
        public bool planningAdd(PlanningBLL u)
        {
            bool success = dalPlanning.Insert(u);

            if (!success)
            {
                MessageBox.Show("Failed to add new production plan!");
                tool.historyRecord(text.System, "Failed to add new production plan!", DateTime.Now, MainDashboard.USER_ID);
            }
            else
            {
                tool.historyRecord(text.plan_Added, text.getNewPlanningDetail(u), DateTime.Now, MainDashboard.USER_ID);

                //get the last record from tbl_planning
                DataTable lastRecord = dalPlanning.lastRecordSelect();

                foreach (DataRow row in lastRecord.Rows)
                {
                    uPlanningAction.planning_id   = Convert.ToInt32(row[dalPlanning.planID]);
                    uPlanningAction.added_date    = Convert.ToDateTime(row[dalPlanning.planAddedDate]);
                    uPlanningAction.added_by      = Convert.ToInt32(row[dalPlanning.planAddedBy]);;
                    uPlanningAction.action        = text.plan_Added;
                    uPlanningAction.action_detail = text.getNewPlanningDetail(u);
                    uPlanningAction.action_from   = "";
                    uPlanningAction.action_to     = "";
                    uPlanningAction.note          = row[dalPlanning.planNote].ToString() + " [Cavity: " + row[dalPlanning.planCavity].ToString() + "; PW(shot): " + row[dalPlanning.planPW].ToString() + " ;RW(shot): " + row[dalPlanning.planRW].ToString() + "]";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningAdd)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningAdd)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }
            }

            return(success);
        }
        //production plan status & schedule change
        public bool planningStatusAndScheduleChange(PlanningBLL u, string presentStatus, DateTime oldStart, DateTime oldEnd, int oldFamilyWith)
        {
            bool success;

            if (u.plan_status == text.planning_status_cancelled || u.plan_status == text.planning_status_running)
            {
                success = dalPlanning.scheduleDataAndRecordingUpdate(u);
            }
            else
            {
                success = dalPlanning.scheduleDataUpdate(u);
            }

            if (!success)
            {
                MessageBox.Show("Failed to change production plan's status & schedule!");
                tool.historyRecord(text.System, "Failed to change production plan's status & schedule!", DateTime.Now, MainDashboard.USER_ID);
            }
            else
            {
                if (!presentStatus.Equals(u.plan_status))
                {
                    tool.historyRecord(text.plan_status_change, "PLAN ID " + u.plan_id + ": " + presentStatus + " --> " + u.plan_status, DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_status_change;
                    uPlanningAction.action_detail = "";
                    uPlanningAction.action_from   = presentStatus;
                    uPlanningAction.action_to     = u.plan_status;
                    uPlanningAction.note          = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningStatusChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningStatusChange)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }

                if (oldStart != u.production_start_date || oldEnd != u.production_end_date)
                {
                    tool.historyRecord(text.plan_schedule_change, "PLAN ID " + u.plan_id + ": " + oldStart.ToShortDateString() + "-" + oldEnd.ToShortDateString() + " --> " + u.production_start_date.ToShortDateString() + "-" + u.production_end_date.ToShortDateString(), DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_schedule_change;
                    uPlanningAction.action_detail = "";
                    string from = oldStart.ToShortDateString() + "-" + oldEnd.ToShortDateString();
                    string to   = u.production_start_date.ToShortDateString() + "-" + u.production_end_date.ToShortDateString();

                    uPlanningAction.action_from = from;
                    uPlanningAction.action_to   = to;
                    uPlanningAction.note        = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningScheduleChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningscheduleChange)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }

                if (u.family_with != oldFamilyWith)
                {
                    tool.historyRecord(text.plan_family_with_change, "PLAN ID " + u.plan_id + ": " + oldFamilyWith + " --> " + u.family_with, DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_family_with_change;
                    uPlanningAction.action_detail = "";
                    uPlanningAction.action_from   = oldFamilyWith.ToString();
                    uPlanningAction.action_to     = u.family_with.ToString();
                    uPlanningAction.note          = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningStatusChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningFamilyWithChange(396))", DateTime.Now, MainDashboard.USER_ID);
                    }
                }
            }

            return(success);
        }
        //production plan schedule and pro day change
        public bool planningScheduleAndProDayChange(PlanningBLL u, string oldProDay, string oldProHour, string oldProHourPerDay, string oldStart, string oldEnd)
        {
            bool success = dalPlanning.scheduleAndProDayUpdate(u);

            if (!success)
            {
                MessageBox.Show("Failed to change production plan's schedule or pro day!");
                tool.historyRecord(text.System, "Failed to change production plan's schedule or pro day!", DateTime.Now, MainDashboard.USER_ID);
            }
            else
            {
                if (u.production_start_date.Date.ToString() != oldStart)
                {
                    tool.historyRecord(text.plan_schedule_change, "PLAN ID " + u.plan_id + " Start Date: " + oldStart + " --> " + u.production_start_date.Date.ToString(), DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_schedule_change;
                    uPlanningAction.action_detail = "";
                    uPlanningAction.action_from   = oldStart;
                    uPlanningAction.action_to     = u.production_start_date.ToShortDateString();
                    uPlanningAction.note          = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }

                if (u.production_end_date.Date.ToString() != oldEnd)
                {
                    tool.historyRecord(text.plan_schedule_change, "PLAN ID " + u.plan_id + " End Date: " + oldEnd + " --> " + u.production_end_date.Date.ToString(), DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_schedule_change;
                    uPlanningAction.action_detail = "";
                    uPlanningAction.action_from   = oldEnd;
                    uPlanningAction.action_to     = u.production_end_date.ToShortDateString();
                    uPlanningAction.note          = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }

                if (u.production_day.ToString() != oldProDay)
                {
                    tool.historyRecord(text.plan_proday_change, "PLAN ID " + u.plan_id + " Pro Day: " + oldProDay + " --> " + u.production_day.ToString(), DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_proday_change;
                    uPlanningAction.action_detail = "";
                    uPlanningAction.action_from   = oldProDay;
                    uPlanningAction.action_to     = u.production_day.ToString();
                    uPlanningAction.note          = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }

                if (u.production_hour.ToString() != oldProHour)
                {
                    tool.historyRecord(text.plan_prohour_change, "PLAN ID " + u.plan_id + " Pro Hour: " + oldProHour + " --> " + u.production_hour.ToString(), DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_prohour_change;
                    uPlanningAction.action_detail = "";
                    uPlanningAction.action_from   = oldProHour;
                    uPlanningAction.action_to     = u.production_hour.ToString();
                    uPlanningAction.note          = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }

                if (u.production_hour_per_day.ToString() != oldProHourPerDay)
                {
                    tool.historyRecord(text.plan_prohourperday_change, "PLAN ID " + u.plan_id + " Pro Hour Per Day: " + oldProHourPerDay + " --> " + u.production_hour_per_day.ToString(), DateTime.Now, MainDashboard.USER_ID);

                    uPlanningAction.planning_id   = u.plan_id;
                    uPlanningAction.added_date    = u.plan_updated_date;
                    uPlanningAction.added_by      = u.plan_updated_by;
                    uPlanningAction.action        = text.plan_prohourperday_change;
                    uPlanningAction.action_detail = "";
                    uPlanningAction.action_from   = oldProHourPerDay;
                    uPlanningAction.action_to     = u.production_hour_per_day.ToString();
                    uPlanningAction.note          = "";

                    bool actionSaveSuccess = Insert(uPlanningAction);

                    if (!actionSaveSuccess)
                    {
                        MessageBox.Show("Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)");
                        tool.historyRecord(text.System, "Failed to save planning action data (planningActionDAL_planningScheduleAndProDayChange)", DateTime.Now, MainDashboard.USER_ID);
                    }
                }
            }

            return(success);
        }
        public string getNewPlanningDetail(PlanningBLL u)
        {
            string detail = u.part_name + "( " + u.part_code + ") :" + u.production_target_qty + " Target QTY run at machine " + u.machine_id;

            return(detail);
        }
예제 #7
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor; // change cursor to hourglass type

            Thread t = null;

            try
            {
                if (Validation())
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure you want to apply this planning?", "Message",
                                                                MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        t = new Thread(new ThreadStart(StartForm));
                        //save planning data
                        DateTime date = DateTime.Now;
                        string   note = txtNote.Text;

                        uPlanning.plan_status = text.planning_status_pending;

                        //check material short
                        uPlanning.plan_note             = note + MatShortRemark();
                        uPlanning.machine_id            = Convert.ToInt32(cmbID.Text);
                        uPlanning.production_start_date = dtpStartDate.Value;
                        uPlanning.production_end_date   = dtpEstimateEndDate.Value;
                        uPlanning.plan_added_date       = date;
                        uPlanning.plan_added_by         = MainDashboard.USER_ID;

                        if (frmMacScheduleAdjust.ToRunPlanFamilyWith != -1)
                        {
                            //check selected plan familywith data
                            int familyWith = tool.getFamilyWithData(frmMacScheduleAdjust.ToRunPlanFamilyWith);

                            //if = -1, get selected plan id
                            if (familyWith == -1)
                            {
                                //update selected plan familyWith and remark data

                                familyWith = frmMacScheduleAdjust.ToRunPlanFamilyWith;

                                DataTable dt_Mac  = dalPlanning.macIDSearch(cmbID.Text.ToString());
                                DataRow   oldData = tool.getDataRowFromDataTableByPlanID(dt_Mac, familyWith.ToString());

                                string oldNote = oldData[dalPlanning.planNote].ToString();

                                PlanningBLL updateFamily = new PlanningBLL();
                                updateFamily.plan_id           = familyWith;
                                updateFamily.plan_note         = text.planning_Family_mould_Remark + oldNote;
                                updateFamily.family_with       = familyWith;
                                updateFamily.plan_updated_date = DateTime.Now;
                                updateFamily.plan_updated_by   = MainDashboard.USER_ID;


                                dalPlanningAction.planningFamilyWithChange(updateFamily, "-1");
                            }


                            if (familyWith == 0)
                            {
                                uPlanning.family_with = -1;
                            }
                            else
                            {
                                uPlanning.family_with = familyWith;
                            }

                            uPlanning.plan_note = text.planning_Family_mould_Remark;
                        }

                        bool success = false;
                        success = dalPlanningAction.planningAdd(uPlanning);


                        if (!success)
                        {
                            //Failed to insert data
                            MessageBox.Show("Failed to save planning data (frmPlanningApply_398)");
                            tool.historyRecord(text.System, "Failed to save planning data (frmPlanningApply_398)", date, MainDashboard.USER_ID);
                        }
                        else
                        {
                            dataSaved = true;
                            tool.historyRecord(text.System, "Planning Data Saved", date, MainDashboard.USER_ID);

                            //save material plan to use qty

                            //DataTable dt = dalMatPlan.Select();

                            if (dt_mat.Rows.Count > 0)
                            {
                                //get planID for this planning
                                int planID = dalPlanning.getLastInsertedPlanID();

                                if (planID != -1)
                                {
                                    foreach (DataRow row in dt_mat.Rows)
                                    {
                                        string matCode   = row[frmPlanning.headerCode].ToString();
                                        float  planToUse = row[frmPlanning.headerQtyNeedForThisPlanning] == null ? 0 : Convert.ToSingle(row[frmPlanning.headerQtyNeedForThisPlanning]);

                                        uMatPlan.mat_code     = matCode;
                                        uMatPlan.plan_id      = planID;
                                        uMatPlan.plan_to_use  = planToUse;
                                        uMatPlan.mat_used     = 0;
                                        uMatPlan.active       = true;
                                        uMatPlan.mat_note     = "";
                                        uMatPlan.updated_date = date;
                                        uMatPlan.updated_by   = MainDashboard.USER_ID;

                                        //tool.matPlanAddQty(dt, matCode, planToUse);

                                        if (!dalMatPlan.Insert(uMatPlan))
                                        {
                                            //MessageBox.Show("Failed to insert material plan data.");
                                            tool.historyRecord(text.System, "Failed to insert material plan data.", date, MainDashboard.USER_ID);
                                        }
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Plan ID not found! Cannot save material plan data.");
                                    tool.historyRecord(text.System, "Plan ID not found! Cannot save material plan data.", date, MainDashboard.USER_ID);
                                }
                            }


                            Close();
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
                // ignore it
                Thread.ResetAbort();
            }
            catch (Exception ex)
            {
                tool.saveToTextAndMessageToUser(ex);
            }
            finally
            {
                if (t != null)
                {
                    t.Abort();
                }
            }

            Cursor = Cursors.Arrow; // change cursor to normal type
        }
        public bool Insert(PlanningBLL u)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                String sql = @"INSERT INTO tbl_plan 
                            (" + planAddedDate + ","
                             + planAddedBy + ","
                             + planStatus + ","
                             + planNote + ","
                             + planCT + ","
                             + planPW + ","
                             + planRW + ","
                             + planCavity + ","
                             + partCode + ","
                             + productionPurpose + ","
                             + materialCode + ","
                             + materialBagQty + ","
                             + materialRecycleUse + ","
                             + colorMaterialCode + ","
                             + colorMaterialUsage + ","
                             + colorMaterialQty + ","
                             + targetQty + ","
                             + ableQty + ","
                             + productionDay + ","
                             + productionHour + ","
                             + productionHourPerDay + ","
                             + productionStartDate + ","
                             + productionEndDate + ","
                             + machineID + ","
                             + familyWith + ") VALUES" +
                             "(@plan_added_date," +
                             "@plan_added_by," +
                             "@plan_status," +
                             "@plan_note," +
                             "@plan_ct," +
                             "@plan_pw," +
                             "@plan_rw," +
                             "@plan_cavity," +
                             "@part_code," +
                             "@production_purpose," +
                             "@material_code," +
                             "@material_bag_qty," +
                             "@material_recycle_use," +
                             "@color_material_code," +
                             "@color_material_usage," +
                             "@color_material_qty," +
                             "@production_target_qty," +
                             "@production_able_produce_qty," +
                             "@production_day," +
                             "@production_hour," +
                             "@production_hour_per_day," +
                             "@production_start_date," +
                             "@production_end_date," +
                             "@machine_id," +
                             "@family_with)";

                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@plan_added_date", u.plan_added_date);
                cmd.Parameters.AddWithValue("@plan_added_by", u.plan_added_by);
                cmd.Parameters.AddWithValue("@plan_status", u.plan_status);
                cmd.Parameters.AddWithValue("@plan_note", u.plan_note);
                cmd.Parameters.AddWithValue("@plan_ct", u.plan_ct);
                cmd.Parameters.AddWithValue("@plan_pw", u.plan_pw);
                cmd.Parameters.AddWithValue("@plan_rw", u.plan_rw);
                cmd.Parameters.AddWithValue("@plan_cavity", u.plan_cavity);
                cmd.Parameters.AddWithValue("@part_code", u.part_code);
                cmd.Parameters.AddWithValue("@production_purpose", u.production_purpose);
                cmd.Parameters.AddWithValue("@material_code", u.material_code);
                cmd.Parameters.AddWithValue("@material_bag_qty", u.material_bag_qty);
                cmd.Parameters.AddWithValue("@material_recycle_use", u.material_recycle_use);
                cmd.Parameters.AddWithValue("@color_material_code", u.color_material_code);
                cmd.Parameters.AddWithValue("@color_material_usage", u.color_material_usage);
                cmd.Parameters.AddWithValue("@color_material_qty", u.color_material_qty);
                cmd.Parameters.AddWithValue("@production_target_qty", u.production_target_qty);
                cmd.Parameters.AddWithValue("@production_able_produce_qty", u.production_able_produce_qty);
                cmd.Parameters.AddWithValue("@production_day", u.production_day);
                cmd.Parameters.AddWithValue("@production_hour", u.production_hour);
                cmd.Parameters.AddWithValue("@production_hour_per_day", u.production_hour_per_day);
                cmd.Parameters.AddWithValue("@production_start_date", u.production_start_date);
                cmd.Parameters.AddWithValue("@production_end_date", u.production_end_date);
                cmd.Parameters.AddWithValue("@machine_id", u.machine_id);
                cmd.Parameters.AddWithValue("@family_with", u.family_with);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                //if the query is executed successfully then the rows' value = 0
                if (rows > 0)
                {
                    //query successful
                    isSuccess = true;
                }
                else
                {
                    //Query falled
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                Module.Tool tool = new Module.Tool(); tool.saveToTextAndMessageToUser(ex);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }