Exemple #1
0
        public FitterMenuViewModel()
        {
            WorksheetRepository repos      = new WorksheetRepository();
            List <Worksheet>    worksheets = new List <Worksheet>();

            WorksheetList = repos.RetrieveAssignedWorksheetsByEmployeeID(ClientInfo.Instance.Employee.ID);
        }
        public static WorksheetRepository GetWorksheetRepository()
        {
            var repository = new WorksheetRepository();

            repository.UnitOfWork = GetUnitOfWork();
            return(repository);
        }
        public static WorksheetRepository GetWorksheetRepository(IUnitOfWork unitOfWork)
        {
            var repository = new WorksheetRepository();

            repository.UnitOfWork = unitOfWork;
            return(repository);
        }
        protected void btnRun_OnClick(object sender, EventArgs e)
        {
            List <Filter> filters    = new List <Filter>();
            var           selectedOp = drpOperator.SelectedValue.ToSafeInt();

            if (selectedOp != -1 && selectedOp != 0)
            {
                filters.Add(new Filter("OperatorId", OperationType.Equals, drpOperator.SelectedValue.ToSafeInt()));
            }
            if (dtFrom.Date != "")
            {
                filters.Add(new Filter("InsertDateTime", OperationType.GreaterThanOrEqual, dtFrom.Date.ToEnDate()));
            }
            if (dtTo.Date != "")
            {
                filters.Add(new Filter("InsertDateTime", OperationType.LessThanOrEqual, dtTo.Date.ToEnDate().AddDays(1).AddSeconds(-1)));
            }
            if (txtPartNo.Text != "")
            {
                filters.Add(new Filter("PartNo", OperationType.Equals, txtPartNo.Text));
            }
            if (txtWaxNo.Text != "")
            {
                filters.Add(new Filter("WaxNo", OperationType.Equals, txtWaxNo.Text));
            }

            var whereClause = filters.Count > 0 ? ExpressionBuilder.GetExpression <WorksheetReportHelper>(filters) : null;

            Session["Result"] = new WorksheetRepository().GetAllForReport(whereClause);
            BindGrid();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var processRepo = new ProcessRepository();
            var finishProductionProcessId = processRepo.Get(a => a.Name == "اتمام تولید").FirstOrDefault().Id;

            CheckShamsiDateFunctions();
            int id;

            if (Page.Request.QueryString[0].ToSafeInt() == 0)
            {
                id = new WorksheetRepository().GetMaxId();
            }
            else
            {
                id = Page.Request.QueryString[0].ToSafeInt();
            }

            Report report = new ReportWorksheets();

            Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource();
            sqlDataSource.ConnectionString = "Tarin";
            sqlDataSource.SelectCommand    =
                "select WID,[Date],PartNo,WaxNo,ColorName,OperatorId,OperatorName,ProcessId,ProcessName from (" +
                "SELECT distinct w.Id WID, dbo.shamsidate(w.Date) as [Date] ,w.PartNo,w.WaxNo,c.Name ColorName, u.FriendlyName OperatorName," +
                //" d.ProductId,p.Code PCode, cat.Name + ' ' + p.Name PName" +
                "    pro.Name ProcessName," +
                "    pro.Id ProcessId," +
                "    cat.Id CatId," +
                "    u.Id OperatorId " +
                //"    pcat.[order] " +
                "FROM worksheets w " +
                "join Colors c on c.Id = w.ColorId " +
                "join Users u on u.Id = w.OperatorId " +
                "join WorksheetDetails d on w.Id = d.WorksheetId " +
                "join Products p on p.Id = d.ProductId " +
                "join Categories cat on cat.Id = p.ProductCategoryId " +
                "join ProcessCategories pcat on pcat.CategoryId = cat.Id " +
                "join Processes pro on pro.Id = pcat.ProcessId" +
                ") s1 " +
                "where WId = @id " +
                "group by WID,[Date],PartNo,WaxNo,ColorName,OperatorId,OperatorName,ProcessId,ProcessName " +
                "order by ProcessId";



            sqlDataSource.Parameters.Add("@id", System.Data.DbType.Int32, id);
            report.DataSource = sqlDataSource;

            InstanceReportSource reportSource = new InstanceReportSource();

            reportSource.ReportDocument = report;

            ReportViewer1.ReportSource = reportSource;

            var table1 = report.Items.Find("table1", true)[0];

            ((table1 as Telerik.Reporting.Table).DataSource as Telerik.Reporting.SqlDataSource).Parameters[0].Value = id;
            ReportViewer1.RefreshReport();
        }
Exemple #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDrpUsers();
                BindDrpColors();

                if (Page.RouteData.Values["Id"].ToSafeInt() != 0)
                {
                    var repo = new WorksheetRepository();
                    var tobeEditedWorksheet = repo.GetByIdWithDetails(Page.RouteData.Values["Id"].ToSafeInt());

                    dtWorksheet.Date          = tobeEditedWorksheet.Date.ToFaDateTime().ToString();
                    txtPart.Text              = tobeEditedWorksheet.PartNo.ToString();
                    txtWaxNo.Text             = tobeEditedWorksheet.WaxNo.ToSafeString();
                    drpColor.SelectedValue    = tobeEditedWorksheet.ColorId.ToString();
                    drpOperator.SelectedValue = tobeEditedWorksheet.OperatorId.ToString();
                    txtDesc.Text              = tobeEditedWorksheet.Desc;
                    var details = new List <WorksheetDetailHelper>();

                    foreach (WorksheetDetail d in tobeEditedWorksheet.WorksheetDetails)
                    {
                        details.Add(new WorksheetDetailHelper()
                        {
                            Id           = d.Id,
                            ProductId    = d.ProductId,
                            ProductName  = d.Product.Name,
                            CategoryId   = d.Product.ProductCategoryId,
                            CategoryName = new CategoryRepository().GetById(d.Product.ProductCategoryId).Name,
                            ACode        = d.ACode
                                           //InsertDateTime = ((DateTime)d.InsertDateTime).ToFaDate(),
                        });
                    }

                    Session["GridSource"] = details;
                }
                else
                {
                    dtWorksheet.LoadCurrentDateTime = true;
                    Session["GridSource"]           = new List <InputHelper>();
                }
            }

            BindTreeview();
            tv1.CollapseAll();

            if (Session["GridSource"] == null)
            {
                Session["GridSource"] = new List <WorksheetDetailHelper>();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDrpOp();

                List <Filter> filters = new List <Filter>();
                filters.Add(new Filter("InsertDateTime", OperationType.GreaterThanOrEqual, DateTime.Now.AddDays(-7)));
                filters.Add(new Filter("InsertDateTime", OperationType.LessThanOrEqual, DateTime.Now));

                var whereClause = ExpressionBuilder.GetExpression <WorksheetReportHelper>(filters);

                Session["Result"] = new WorksheetRepository().GetAllForReport(whereClause);
            }

            BindGrid();
        }
Exemple #8
0
        public WorksheetViewModel(Customer customer)
        {
            // Init start values
            Customer          = customer;
            AssignedEmployees = new ObservableCollection <Employee>();
            Images            = new ObservableCollection <Image>();
            Materials         = new ObservableCollection <Material>();
            WorkHours         = new ObservableCollection <WorkHours>();
            WorkDescription   = "";
            Workplace         = customer.Address.ToString();
            _status           = Status.Waiting;

            IsServiceVehicleChecked     = false;
            IsAuxiliaryMaterialsChecked = false;

            Hours = new List <TimeSpan>();
            for (int i = 6; i <= 21; i++)
            {
                Hours.Add(new TimeSpan(i, 0, 0));
            }

            Minutes = new List <TimeSpan>();
            for (int i = 0; i < 60; i += 15)
            {
                Minutes.Add(new TimeSpan(0, i, 0));
            }

            StartTime = new TimeSpan(6, 0, 0);
            EndTime   = new TimeSpan(6, 0, 0);

            StartDate = DateTime.Today;
            EndDate   = DateTime.Today;

            //Save temp in Database to get ID
            worksheetRepository = new WorksheetRepository();
            Worksheet worksheet = worksheetRepository.Create(GetWorksheet());

            WorksheetID = worksheet.ID;
        }
Exemple #9
0
        public static string AddRow(string input)
        {
            //WID,OperatorID,ProcessID
            var parts = input.Replace('و', ',').Split(',');

            var worksheetId = parts[0].ToSafeInt();
            var operatorId  = parts[1].ToSafeInt();
            var processId   = parts[2].ToSafeInt();

            var workLinerepo           = new WorkLineRepository();
            var thisWorksheetWorkLines = workLinerepo.Get(a => a.WorksheetId == worksheetId);

            var prevProcessOfThisWorksheet = thisWorksheetWorkLines.Any() ? thisWorksheetWorkLines.Where(a => a.ProcessId != 999).Max(a => a.ProcessId) : 0;

            if (prevProcessOfThisWorksheet != 999)
            {
                if (thisWorksheetWorkLines != null && thisWorksheetWorkLines.Any())
                {
                    if (prevProcessOfThisWorksheet != 0 && prevProcessOfThisWorksheet >= processId)
                    {
                        return("عدم رعایت ترتیب فرآیند" + "- کاربر:" + new UserRepository().GetById(operatorId)?.Username + "- کاربرگ:" + worksheetId);
                    }
                }
            }

            if (HttpContext.Current.Session["worksheetProcesses" + "#" + worksheetId] == null)
            {
                var wsheetProcesses = new WorksheetRepository().GetWorksheetProcesses(worksheetId);
                if (wsheetProcesses == null)
                {
                    return("کاربرگ ردیف ندارد");
                }

                HttpContext.Current.Session["worksheetProcesses" + "#" + worksheetId] = wsheetProcesses;
            }

            var thisWorksheetProcesses     = (List <int>)HttpContext.Current.Session["worksheetProcesses" + "#" + worksheetId];
            var indexOfPrevProcess         = thisWorksheetProcesses.IndexOf(prevProcessOfThisWorksheet);
            var indexOfNextProcess         = indexOfPrevProcess + 1;
            var nextProcessOfThisWorksheet = thisWorksheetProcesses[indexOfNextProcess];

            if (processId != 999 && processId != nextProcessOfThisWorksheet)
            {
                return("عدم رعایت ترتیب فرآیند" + "- کاربر:" + new UserRepository().GetById(operatorId)?.Username + "- کاربرگ:" + worksheetId);
            }


            var uow = new UnitOfWork();

            uow.WorkLines.Create(new Repository.Entity.Domain.WorkLine()
            {
                InsertDateTime = DateTime.Now,
                WorksheetId    = worksheetId,
                OperatorId     = operatorId,
                //ProductId = productId,
                ProcessId = processId
            }
                                 );

            var result = uow.SaveChanges();

            if (result.IsSuccess)
            {
                HttpContext.Current.Session[worksheetId + "#" + operatorId] = processId;
                return("OK");
            }
            else
            {
                //((Main)Page.Master).SetGeneralMessage("خطا در ذخیره اطلاعات", MessageType.Error);
                Debuging.Error(result.ResultCode + "," + result.Message + "," + result.Message);
                return("خطا در اضافه کردن ردیف");
            }
        }
        private void LoadDT(int wid)
        {
            WorklineDT().Rows.Clear();

            var allowedPrTimes = new WorksheetRepository().GetWorksheetAllowedPrTimes(wid);

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Anaraki"].ToString()))
            {
                var selectCommand =
                    "select WID,[Date],PartNo,WaxNo,ColorName,OperatorId,OperatorName,ProcessId,ProcessName,Cast('' as char(5)) Time,Cast(0 as int) Hour,Cast(0 as int) Min from (" +
                    "SELECT distinct w.Id WID, dbo.shamsidate(w.Date) as [Date] ,w.PartNo,w.WaxNo,c.Name ColorName, u.FriendlyName OperatorName," +
                    "    pro.Name ProcessName," +
                    "    pro.Id ProcessId," +
                    "    cat.Id CatId," +
                    "    u.Id OperatorId " +
                    "FROM worksheets w " +
                    "join Colors c on c.Id = w.ColorId " +
                    "join Users u on u.Id = w.OperatorId " +
                    "join WorksheetDetails d on w.Id = d.WorksheetId " +
                    "join Products p on p.Id = d.ProductId " +
                    "join Categories cat on cat.Id = p.ProductCategoryId " +
                    "join ProcessCategories pcat on pcat.CategoryId = cat.Id " +
                    "join Processes pro on pro.Id = pcat.ProcessId" +
                    ") s1 " +
                    "where WId = @id " +
                    "group by WID,[Date],PartNo,WaxNo,ColorName,OperatorId,OperatorName,ProcessId,ProcessName " +
                    "order by ProcessId";

                connection.Open();

                SqlCommand sqlCommand = new SqlCommand(selectCommand, connection);
                sqlCommand.Parameters.AddWithValue("@id", wid);

                SqlDataReader reader = sqlCommand.ExecuteReader();

                var now = DateTime.Now;

                var zeroTime = new DateTime(now.Year, now.Month, now.Day, 8, 0, 0);

                if (reader.HasRows)
                {
                    var dt = WorklineDT();
                    int i  = 0;

                    while (reader.Read())
                    {
                        var newRow = dt.NewRow();

                        //dt.Columns.Add(new DataColumn("Id", typeof(int)));
                        //dt.Columns.Add(new DataColumn("ProcessId", typeof(int)));
                        //dt.Columns.Add(new DataColumn("ProcessName", typeof(string)));
                        //dt.Columns.Add(new DataColumn("OperatorId", typeof(int)));
                        //dt.Columns.Add(new DataColumn("OperatorName", typeof(int)));
                        //dt.Columns.Add(new DataColumn("WorksheetId", typeof(int)));
                        //dt.Columns.Add(new DataColumn("InsertDateTime", typeof(DateTime)));
                        //dt.Columns.Add(new DataColumn("Date", typeof(string)));
                        //dt.Columns.Add(new DataColumn("Time", typeof(string)));

                        newRow["Hour"] = zeroTime.Hour;
                        newRow["Min"]  = zeroTime.Minute;

                        var prId = reader.GetInt32(7);

                        newRow["Id"]          = i++;
                        newRow["Date"]        = reader.GetString(1).ToString().Substring(0, 10);
                        newRow["ProcessId"]   = prId;
                        newRow["ProcessName"] = reader.GetString(8);
                        newRow["OperatorId"]  = reader.GetInt32(5);

                        var allowedPrTime = allowedPrTimes.FirstOrDefault(a => a.ProcessId == prId).ProcessTime;
                        zeroTime = zeroTime.AddMinutes(allowedPrTime);

                        dt.Rows.Add(newRow);
                    }
                }

                reader.Close();
            }
        }
Exemple #11
0
 public static WorksheetRepository GetWorksheetRepository(IUnitOfWork unitOfWork)
 {
     var repository = new WorksheetRepository();
     repository.UnitOfWork = unitOfWork;
     return repository;
 }
Exemple #12
0
 public static WorksheetRepository GetWorksheetRepository()
 {
     var repository = new WorksheetRepository();
     repository.UnitOfWork = GetUnitOfWork();
     return repository;
 }
Exemple #13
0
        public static string AddRow(string input, string reworkACodes, string reworkReasons, string reworkDesc, string reworkEsghatMode, string reworkEsghatPrevProcessId)
        {
            //WID,OperatorID,ProcessID
            var parts = input.Replace('و', ',').Split(',');

            var worksheetId = parts[0].ToSafeInt();
            var operatorId  = parts[1].ToSafeInt();
            var processId   = parts[2].Replace("#", "").ToSafeInt();

            var workLinerepo           = new WorkLineRepository();
            var thisWorksheetWorkLines = workLinerepo.Get(a => a.WorksheetId == worksheetId);

            var prevProcessIsEsghat = thisWorksheetWorkLines.Any() ? thisWorksheetWorkLines.Any(a => a.ProcessId == 1001) : false;

            if (prevProcessIsEsghat)
            {
                return("پس از اسقاط قادر به ثبت فرآیند دیگری نیستید");
            }

            var actualPrevProcess = thisWorksheetWorkLines.Any() ? thisWorksheetWorkLines.OrderByDescending(a => a.Id).FirstOrDefault().ProcessId : 0;
            //var breforePrevProcessOfThisWorksheet = thisWorksheetWorkLines.Any() ? thisWorksheetWorkLines.Where(a=>a.ProcessId != 999 && a.ProcessId != 1000 && a.ProcessId != 1001 && a.ProcessId != 1002).Max(a => a.ProcessId) : 0;
            var prevProcessOfThisWorksheet = thisWorksheetWorkLines.Any() ? thisWorksheetWorkLines.Where(a => a.ProcessId != 999 && a.ProcessId != 1000 && a.ProcessId != 1001 && a.ProcessId != 1002).Max(a => a.ProcessId) : 0;


            if (actualPrevProcess == 1002 && prevProcessOfThisWorksheet == processId)
            {
                //after launch previous process can be continued
            }
            else
            if (processId != 1000 && processId != 1001 && processId != 1002)
            {
                if (thisWorksheetWorkLines != null && thisWorksheetWorkLines.Any())
                {
                    if (prevProcessOfThisWorksheet != 0 && prevProcessOfThisWorksheet >= processId)
                    {
                        return("عدم رعایت ترتیب فرآیند" + "- کاربر:" + new UserRepository().GetById(operatorId)?.Username + "- کاربرگ:" + worksheetId);
                    }
                }
            }

            if (HttpContext.Current.Session["worksheetProcesses" + "#" + worksheetId] == null)
            {
                var wsheetProcesses = new WorksheetRepository().GetWorksheetProcesses(worksheetId);
                if (wsheetProcesses == null)
                {
                    return("کاربرگ ردیف ندارد");
                }

                HttpContext.Current.Session["worksheetProcesses" + "#" + worksheetId] = wsheetProcesses;
            }

            if (processId != 999 && processId != 1000 && processId != 1001 && processId != 1002) // 999 etmame movaghat, 1000 rework, 1001 esghat,1002 nahar
            {
                var thisWorksheetProcesses     = (List <int>)HttpContext.Current.Session["worksheetProcesses" + "#" + worksheetId];
                var indexOfPrevProcess         = thisWorksheetProcesses.IndexOf(prevProcessOfThisWorksheet);
                var indexOfNextProcess         = indexOfPrevProcess + 1;
                var nextProcessOfThisWorksheet = thisWorksheetProcesses[indexOfNextProcess];

                if (processId != nextProcessOfThisWorksheet && !(actualPrevProcess == 1002 && prevProcessOfThisWorksheet == processId))
                {
                    return("عدم رعایت ترتیب فرآیند" + "- کاربر:" + new UserRepository().GetById(operatorId)?.Username + "- کاربرگ:" + worksheetId);
                }
            }

            var uow = new UnitOfWork();

            if (processId != 999 && processId != 1000 && processId != 1001)
            {
                var wl = uow.WorkLines.Get(a => a.WorksheetId == worksheetId && a.OperatorId == operatorId && a.ProcessId == processId);
                if (wl?.Count != 0 && !(actualPrevProcess == 1002 && prevProcessOfThisWorksheet == processId))
                {
                    return($"فرآیند با این مشخصات قبلا ثبت شده کاربر:{new UserRepository().GetById(operatorId)?.Username} ");
                }
            }
            else
            {
                var intReworkEsghatPrevProcessId = reworkEsghatPrevProcessId.ToSafeInt();

                if (processId == 1000)
                {
                    var rw = uow.Reworks.Get(a => a.WorksheetId == worksheetId && a.PrevProcessId == intReworkEsghatPrevProcessId);
                    if (rw?.Count != 0)
                    {
                        return("برای این فرآیند قبلا دوباره کاری ثبت شده است");
                    }
                }
                else if (processId == 1001)
                {
                    var rw = uow.Esghats.Get(a => a.WorksheetId == worksheetId && a.PrevProcessId == intReworkEsghatPrevProcessId);
                    if (rw?.Count != 0)
                    {
                        return("برای این فرآیند قبلا اسقاط ثبت شده است");
                    }
                }
            }

            var newWorkLine = uow.WorkLines.Create(new Repository.Entity.Domain.WorkLine()
            {
                InsertDateTime = DateTime.Now,
                WorksheetId    = worksheetId,
                OperatorId     = operatorId,
                ProcessId      = processId
            }
                                                   );

            var acodes  = reworkACodes.Split(',');
            var reasons = reworkReasons.Split(',');

            if (acodes.Contains("-1"))
            {
                return("علت انتخاب نشده");
            }

            if (reworkEsghatMode != "")
            {
                if (reworkEsghatMode.ToLower() == "rework")
                {
                    var newRework = uow.Reworks.Create(new Repository.Entity.Domain.Rework()
                    {
                        InsertDateTime = DateTime.Now,
                        OperatorId     = operatorId,
                        InsertedUserId = operatorId,  //?
                        Desc           = reworkDesc,
                        PrevProcessId  = reworkEsghatPrevProcessId.ToSafeInt(),
                        WorksheetId    = worksheetId,
                        Status         = -1,
                    });

                    if (acodes.Any())
                    {
                        newRework.ReworkDetails = new List <ReworkDetail>();

                        for (int i = 0; i < acodes.Length; i++)
                        {
                            newRework.ReworkDetails.Add(new ReworkDetail {
                                ACode = acodes[i], ReworkReasonId = reasons[i].ToSafeInt()
                            });
                        }
                    }

                    newWorkLine.Rework = newRework;
                }
                else
                {
                    var newEsghat = uow.Esghats.Create(new Repository.Entity.Domain.Esghat()
                    {
                        InsertDateTime = DateTime.Now,
                        OperatorId     = operatorId,
                        InsertedUserId = operatorId,  //?
                        Desc           = reworkDesc,
                        PrevProcessId  = reworkEsghatPrevProcessId.ToSafeInt(),
                        WorksheetId    = worksheetId,
                        Status         = -1
                    });

                    if (acodes.Any())
                    {
                        newEsghat.EsghatDetails = new List <EsghatDetail>();

                        for (int i = 0; i < acodes.Length; i++)
                        {
                            newEsghat.EsghatDetails.Add(new EsghatDetail {
                                ACode = acodes[i], ReworkReasonId = reasons[i].ToSafeInt()
                            });
                        }
                    }

                    newWorkLine.Esghat = newEsghat;
                }
            }

            var result = uow.SaveChanges();

            if (result.IsSuccess)
            {
                HttpContext.Current.Session[worksheetId + "#" + operatorId] = processId;
                return("OK");
            }
            else
            {
                //((Main)Page.Master).SetGeneralMessage("خطا در ذخیره اطلاعات", MessageType.Error);
                Debuging.Error(result.ResultCode + "," + result.Message + "," + result.Message);
                return("خطا در اضافه کردن ردیف");
            }
        }