public bool editDetail(ProductionLineInfoModel detail, int prid)
        {
            bool result = false;
            var  tbl    = (from t in context.PP_ScheduleProductionLineInfos
                           where
                           t.ScheduleProductionLineID == detail.ScheduleProductionLineID
                           select t).FirstOrDefault();

            //DataLayer.PP_ScheduleProductionLineInfo tbl = new DataLayer.PP_ScheduleProductionLineInfo();
            tbl.ProductionLineID         = prid;
            tbl.ScheduleID               = detail.ScheduleID;
            tbl.ScheduleProductionLineID = (int)detail.ScheduleProductionLineID;
            tbl.CycleTime         = detail.CycleTime;
            tbl.ScheduleStartTime = detail.ScheduleStartTime;
            tbl.DurationTime      = detail.DurationTime;
            tbl.Date = detail.Date;
            tbl.ScheduleFinishTime = detail.ScheduleFinishTime;
            tbl.Year           = returnYear(detail.Date);
            tbl.Month          = returnMonth(detail.Date);
            tbl.Day            = returnDay(detail.Date);
            tbl.RoutID         = detail.RoutID;
            tbl.InputID        = detail.InputID;
            tbl.YearID         = CRMStaticData.StaticData.getYearID;
            tbl.UserID         = CRMStaticData.StaticData.getUserID;
            tbl.BranchID       = CRMStaticData.StaticData.getBranchID;
            tbl.RegisteredDate = CRMStaticData.StaticData.DateNow(0).Date;
            // context.PP_ScheduleProductionLineInfos.InsertOnSubmit(tbl);
            context.SubmitChanges();
            result = true;
            return(result);
        }
        /// <summary>
        /// this function conver the table form to model
        /// </summary>
        /// <param name="tbl"></param> the covertable table
        /// <returns></returns>the converted model
        public ProductionLineInfoModel ConvertToModel(DataLayer.PP_ProductionLineInfo tbl)
        {
            ProductionLineInfoModel model = new ProductionLineInfoModel();
            var res         = context.PP_WorkersInfos.Where(q => q.WorkersID == tbl.ResponsibleID).FirstOrDefault();
            var sche        = context.PP_ScheduleProductionLineInfos.Where(q => q.ProductionLineID == tbl.ProductionLineID).FirstOrDefault();
            var shiftstatus = context.PP_ProductionLineInfos.Where(q => q.Shift == tbl.Shift).FirstOrDefault();

            model.ProductionLineID = tbl.ProductionLineID;
            // model.ProductionLineStop = tbl.ProductionLineStop;
            model.ResponsibleID   = tbl.ResponsibleID;
            model.ResponsibleName = (res == null)?"-":res.WorkersSurname;
            model.WorkStationID   = tbl.WorkStationID;
            model.Shift           = tbl.Shift;
            if (shiftstatus != null)
            {
                if (tbl.Shift == 1)
                {
                    model.ShiftName = "شب";
                }
                if (tbl.Shift == 2)
                {
                    model.ShiftName = "روز";
                }
            }
            // model.LineAcceptance = tbl.LineAcceptance;
            // model.LineEfficiency = tbl.LineEfficiency;
            //model.LineGoal = tbl.LineGoal;
            model.RoutID = tbl.RoutID;
            model.YearID = tbl.YearID;
            model.UserID = tbl.UserID;
            if (sche != null)
            {
                model.RegisteredDate = sche.Date;
            }
            else
            {
                model.RegisteredDate = tbl.RegisteredDate;
            }
            model.BranchID = tbl.BranchID;
            //  model.RoutName = context.PP_RoutInfos.Where(q => q.RoutID == tbl.RoutID).FirstOrDefault().RoutName;
            if (context.PP_WorkStationInfos.Where(q => q.WorkStationID == tbl.WorkStationID).FirstOrDefault() != null)
            {
                model.WorkStationName = context.PP_WorkStationInfos.Where(q => q.WorkStationID == tbl.WorkStationID).FirstOrDefault().WorkStationName;
            }
            if (sche != null)
            {
                model.ScheduleProductionLineID = sche.ScheduleProductionLineID;
            }
            return(model);
        }
        /// <summary>
        /// this function copy the model for edit
        /// </summary>
        /// <param name="model"></param> the model should be edited
        /// <returns></returns> returns if the copy is successfull
        public Boolean Edit(ProductionLineInfoModel model)
        {
            Boolean result = true;

            try
            {
                IsEdit = true;
                _model = model;
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
        /// <summary>
        /// this function copy the models to save
        /// </summary>
        /// <param name="model"></param> the copyable model
        /// <returns></returns> returns if the copy is successfull
        public Boolean Add(ProductionLineInfoModel model)
        {
            Boolean result = true;

            try
            {
                _model                = model;
                _model.BranchID       = CRMStaticData.StaticData.getBranchID;
                _model.RegisteredDate = CRMStaticData.StaticData.getRegisteredDate;
                _model.UserID         = CRMStaticData.StaticData.getUserID;
                _model.YearID         = CRMStaticData.StaticData.getYearID;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(result);
        }
 /// <summary>
 /// this function convert the model to table form
 /// </summary>
 /// <param name="model"></param> the convertable model
 /// <returns></returns> returns the converted table
 public DataLayer.PP_ProductionLineInfo ConvertToTable(ProductionLineInfoModel model)
 {
     DataLayer.PP_ProductionLineInfo tbl = new DataLayer.PP_ProductionLineInfo();
     tbl.ProductionLineID   = model.ProductionLineID;
     tbl.ProductionLineStop = model.ProductionLineStop;
     tbl.WorkStationID      = model.WorkStationID;
     tbl.LineAcceptance     = model.LineAcceptance;
     tbl.LineEfficiency     = model.LineEfficiency;
     tbl.LineGoal           = model.LineGoal;
     tbl.Shift          = model.Shift;
     tbl.RoutID         = model.RoutID;
     tbl.YearID         = model.YearID;
     tbl.UserID         = model.UserID;
     tbl.RegisteredDate = model.RegisteredDate;
     tbl.BranchID       = model.BranchID;
     tbl.ResponsibleID  = model.ResponsibleID;
     return(tbl);
 }
 public void saveDetail(ProductionLineInfoModel item, int MasterID)
 {
     DataLayer.PP_ScheduleProductionLineInfo tbl = new DataLayer.PP_ScheduleProductionLineInfo();
     tbl.ProductionLineID  = MasterID;
     tbl.ScheduleID        = item.ScheduleID;
     tbl.CycleTime         = item.CycleTime;
     tbl.ScheduleStartTime = item.ScheduleStartTime;
     tbl.DurationTime      = item.DurationTime;
     tbl.Date = item.Date;
     tbl.ScheduleFinishTime = item.ScheduleFinishTime;
     tbl.Year           = returnYear(item.Date);
     tbl.Month          = returnMonth(item.Date);
     tbl.Day            = returnDay(item.Date);
     tbl.RoutID         = item.RoutID;
     tbl.InputID        = item.InputID;
     tbl.YearID         = CRMStaticData.StaticData.getYearID;
     tbl.UserID         = CRMStaticData.StaticData.getUserID;
     tbl.BranchID       = CRMStaticData.StaticData.getBranchID;
     tbl.RegisteredDate = CRMStaticData.StaticData.DateNow(0).Date;
     context.PP_ScheduleProductionLineInfos.InsertOnSubmit(tbl);
     context.SubmitChanges();
 }