public ProductReleaseDateViewModel(UserInformation userInformation, System.Windows.Window window, ProductInformationModel productInformationModel,
                                    ProcessDesigner.Common.OperationMode operationMode, string title = "Document Release Date")
 {
     PRODUCT_INFORMATION_MODEL = (productInformationModel.IsNotNullOrEmpty() ? productInformationModel : new ProductInformationModel());
     if (!_productInformationModel.DOC_REL_DATE.IsNotNullOrEmpty())
     {
         FeasibleReportAndCostSheet bll = new FeasibleReportAndCostSheet(userInformation);
         _productInformationModel.DOC_REL_DATE = bll.ServerDateTime();
     }
     this.saveCommand = new DelegateCommand(this.SaveSubmitCommand);
 }
        private void SaveSubmitCommand()
        {
            if (!OldActiveEntity.IsNotNullOrEmpty())
            {
                return;
            }
            if (!NewActiveEntity.IsNotNullOrEmpty())
            {
                return;
            }

            if (!OldActiveEntity.CI_REFERENCE.IsNotNullOrEmpty())
            {
                ShowInformationMessage(PDMsg.NotEmpty("Old CI Reference Number"));
                return;
            }

            if (!NewActiveEntity.CI_REFERENCE.IsNotNullOrEmpty())
            {
                ShowInformationMessage(PDMsg.NotEmpty("New CI Reference Number"));
                return;
            }

            if (OldActiveEntity.CI_REFERENCE.Trim() == NewActiveEntity.CI_REFERENCE.Trim())
            {
                ShowInformationMessage("CI Reference Numbers should not be same");
                return;
            }

            string           message;
            List <DDCI_INFO> lstResult = null;

            if (!bll.IsValidCIReferenceNumber(OldActiveEntity, OperationMode.Edit, out message) &&
                message.IsNotNullOrEmpty() && !(message.IndexOf("already exists") >= 0))
            {
                //ShowInformationMessage(message);
                //return;

                lstResult = (from row in bll.GetEntitiesByCIReferenceNumber(OldActiveEntity)
                             select row).ToList <DDCI_INFO>();

                if (lstResult.IsNotNullOrEmpty() && lstResult.Count == 0)
                {
                    ShowInformationMessage(PDMsg.DoesNotExists("Old CI Reference"));
                    return;
                }
            }

            lstResult = (from row in bll.GetEntitiesByCIReferenceNumber(OldActiveEntity)
                         select row).ToList <DDCI_INFO>();

            if (lstResult.IsNotNullOrEmpty() && lstResult.Count == 0)
            {
                ShowInformationMessage(PDMsg.DoesNotExists("Old CI Reference"));
                return;
            }

            lstResult = (from row in bll.GetEntitiesByCIReferenceNumber(NewActiveEntity)
                         select row).ToList <DDCI_INFO>();

            if (lstResult.IsNotNullOrEmpty() && lstResult.Count > 0)
            {
                message = PDMsg.AlreadyExists("CI Reference Number");
                message = message.IndexOf("already exists") >= 0 ?
                          "CI Reference Number " + NewActiveEntity.CI_REFERENCE + " already exists.\r\nEnter/Select another CI Reference Number" :
                          message;
                ShowInformationMessage(message);
                return;
            }

            string outMessage;

            if (!bll.IsValidCIReferenceNumber(NewActiveEntity, ActionMode, out outMessage) && outMessage.IsNotNullOrEmpty())
            {
                ShowInformationMessage(outMessage);
                return;
            }

            if (OldActiveEntity.RM_COST > 9999999999.99m)
            {
                ShowInformationMessage(PDMsg.NotExceeds("Cost for 100 Pcs", "9999999999.99"));
                return;
            }

            if (OldActiveEntity.FINAL_COST > 9999999999.99m)
            {
                ShowInformationMessage(PDMsg.NotExceeds("Cost for " + OldActiveEntity.NO_OF_PCS + " Pcs", "9999999999.99"));
                return;
            }

            if (OldActiveEntity.REALISATION > 99999999.99m)
            {
                ShowInformationMessage(PDMsg.NotExceeds("Realisation", "99999999.99"));
                return;
            }

            try
            {
                //List<DDCI_INFO> lstResult = null;
                List <DDCOST_PROCESS_DATA> lstAssociationEntity = null;

                bool isExecuted = false;
                switch (ActionMode)
                {
                case OperationMode.AddNew:
                    #region Add Operation

                    foreach (DDCOST_PROCESS_DATA associationEntity in OldActiveEntity.DDCOST_PROCESS_DATA)
                    {
                        OldActiveEntity.DDCOST_PROCESS_DATA.Remove(associationEntity);
                    }

                    string   newCIReferenceNumber = NewActiveEntity.CI_REFERENCE;
                    DateTime?newENQU_RECD_ON      = NewActiveEntity.ENQU_RECD_ON;
                    string   newZONE_CODE         = NewActiveEntity.ZONE_CODE;

                    DDCI_INFO activeEntity = OldActiveEntity.DeepCopy <DDCI_INFO>();
                    activeEntity.IDPK         = -99999;
                    activeEntity.CI_REFERENCE = newCIReferenceNumber;
                    activeEntity.ENQU_RECD_ON = newENQU_RECD_ON;
                    activeEntity.ZONE_CODE    = newZONE_CODE;

                    activeEntity.CUST_DWG_NO       = null;
                    activeEntity.CUST_DWG_NO_ISSUE = null;
                    activeEntity.FR_CS_DATE        = bll.ServerDateTime();

                    string syear = newCIReferenceNumber.Substring(1, 2).ToIntValue() == 0 ?
                                   "20" + newCIReferenceNumber.Substring(1, 2) : newCIReferenceNumber.Substring(1, 2);

                    string smonth = newCIReferenceNumber.Substring(3, 2);
                    string sday   = newCIReferenceNumber.Substring(5, 2);

                    try
                    {
                        DateTime receivedOn = new DateTime(syear.ToIntValue(), smonth.ToIntValue(), sday.ToIntValue());
                        activeEntity.ENQU_RECD_ON = receivedOn;
                    }
                    catch (Exception ex)
                    {
                        throw ex.LogException();
                    }

                    foreach (DDCOST_PROCESS_DATA associationEntity in activeEntity.DDCOST_PROCESS_DATA)
                    {
                        activeEntity.DDCOST_PROCESS_DATA.Remove(associationEntity);
                    }

                    isExecuted = bll.Update <DDCI_INFO>(new List <DDCI_INFO>()
                    {
                        activeEntity
                    });

                    if (isExecuted)
                    {
                        activeEntity = (from row in bll.GetEntitiesByCIReferenceNumber(activeEntity)
                                        select row).SingleOrDefault <DDCI_INFO>();
                        if (activeEntity.IsNotNullOrEmpty())
                        {
                            lstAssociationEntity = (from row in bll.GetCostDetails(OldActiveEntity)
                                                    select new DDCOST_PROCESS_DATA()
                            {
                                CI_REFERENCE = newCIReferenceNumber,
                                SNO = Convert.ToDecimal(row.SNO),
                                OPERATION_NO = Convert.ToDecimal(row.OPERATION_NO),
                                OPERATION = row.OPERATION,
                                COST_CENT_CODE = row.COST_CENT_CODE,
                                OUTPUT = row.OUTPUT,
                                VAR_COST = row.VAR_COST,
                                FIX_COST = row.FIX_COST,
                                SPL_COST = row.SPL_COST,
                                UNIT_OF_MEASURE = row.UNIT_OF_MEASURE,
                                TOTAL_COST = row.TOTAL_COST,
                                IDPK = -99999,
                                CI_INFO_FK = activeEntity.IDPK,
                                ROWID = Guid.NewGuid(),
                                PROCESS_CODE = Convert.ToDecimal(row.PROCESS_CODE),
                            }).ToList <DDCOST_PROCESS_DATA>();
                            if (lstAssociationEntity.IsNotNullOrEmpty() && lstAssociationEntity.Count == 0)
                            {
                                ShowInformationMessage("No Process Data to Copy");
                            }
                            else
                            {
                                isExecuted = bll.Update <DDCOST_PROCESS_DATA>(lstAssociationEntity);
                            }

                            List <DDSHAPE_DETAILS> lstFinishWeightCalculation = null;
                            lstFinishWeightCalculation = (from row in bll.GetShapeDetails(OldActiveEntity)
                                                          select new DDSHAPE_DETAILS()
                            {
                                CI_REFERENCE = newCIReferenceNumber,
                                SHAPE_CODE = row.SHAPE_CODE,
                                WEIGHT_OPTION = row.WEIGHT_OPTION,
                                HEAD1 = row.HEAD1,
                                VAL1 = row.VAL1,
                                HEAD2 = row.HEAD2,
                                VAL2 = row.VAL2,
                                HEAD3 = row.HEAD3,
                                VAL3 = row.VAL3,
                                VOLUME = row.VOLUME,
                                SIGN = row.SIGN,
                                SNO = row.SNO,
                                ROWID = row.ROWID,
                                IDPK = -99999,
                                CIREF_NO_FK = activeEntity.IDPK,
                            }).ToList <DDSHAPE_DETAILS>();
                            if (lstFinishWeightCalculation.IsNotNullOrEmpty() && lstFinishWeightCalculation.Count == 0)
                            {
                                ShowInformationMessage("No Weight Calculation Data to Copy");
                            }
                            else
                            {
                                Progress.ProcessingText = PDMsg.ProgressUpdateText;
                                Progress.Start();
                                isExecuted = bll.Update <DDSHAPE_DETAILS>(lstFinishWeightCalculation);
                                Progress.End();
                            }
                            if (isExecuted)
                            {
                                ShowInformationMessage(PDMsg.SavedSuccessfully);
                                NewActiveEntity = activeEntity.DeepCopy <DDCI_INFO>();
                                NewActiveEntity.CI_REFERENCE = string.Empty;
                                NewActiveEntity.ENQU_RECD_ON = newENQU_RECD_ON;
                                NewActiveEntity.ZONE_CODE    = newZONE_CODE;
                            }
                        }
                    }
                    #endregion
                    break;

                case OperationMode.Edit:
                    //#region Update Operation
                    //lstResult = (from row in bll.DB.DDCI_INFO
                    //             where row.CUST_DWG_NO == ActiveEntity.CUST_DWG_NO
                    //             select row).ToList<DDCI_INFO>();

                    //if (lstResult.IsNotNullOrEmpty() && lstResult.Count > 1)
                    //{
                    //    ShowInformationMessage("Customer Drawing Number already exists");
                    //    return;
                    //}

                    //lstStandardNotes = (from row in StandardNotes.ToTable().AsEnumerable()
                    //                    select new DDSTD_NOTES()
                    //                    {
                    //                        SNO = Convert.ToDecimal(row.Field<string>("SNO")),
                    //                        STD_NOTES = row.Field<string>("STD_NOTES"),
                    //                        ROWID = Guid.NewGuid(),
                    //                    }
                    //    ).ToList<DDSTD_NOTES>();

                    //isExecuted = bll.Update<DDSTD_NOTES>(lstStandardNotes);

                    //foreach (DDCOST_PROCESS_DATA associationEntity in ActiveEntity.DDCOST_PROCESS_DATA)
                    //{
                    //    ActiveEntity.DDCOST_PROCESS_DATA.Remove(associationEntity);
                    //}
                    //lstAssociationEntity = (from row in CostDetails.ToTable().AsEnumerable()
                    //                        select new DDCOST_PROCESS_DATA()
                    //                        {
                    //                            CI_REFERENCE = ActiveEntity.CI_REFERENCE,
                    //                            SNO = Convert.ToDecimal(row.Field<string>("SNO")),
                    //                            OPERATION_NO = Convert.ToDecimal(row.Field<string>("OPERATION_NO")),
                    //                            OPERATION = row.Field<string>("OPERATION"),
                    //                            COST_CENT_CODE = row.Field<string>("COST_CENT_CODE"),
                    //                            OUTPUT = Convert.ToDecimal(row.Field<string>("OUTPUT")),
                    //                            VAR_COST = Convert.ToDecimal(row.Field<string>("VAR_COST")),
                    //                            FIX_COST = Convert.ToDecimal(row.Field<string>("FIX_COST")),
                    //                            SPL_COST = Convert.ToDecimal(row.Field<string>("SPL_COST")),
                    //                            UNIT_OF_MEASURE = row.Field<string>("UNIT_OF_MEASURE"),
                    //                            TOTAL_COST = Convert.ToDecimal(row.Field<string>("TOTAL_COST")),
                    //                            IDPK = Convert.ToInt32(row.Field<string>("IDPK")),
                    //                            CI_INFO_FK = ActiveEntity.IDPK,
                    //                            ROWID = row.Field<string>("ROWID").ToGuidValue(),
                    //                        }).ToList<DDCOST_PROCESS_DATA>();

                    //isExecuted = bll.Update<DDCOST_PROCESS_DATA>(lstAssociationEntity);

                    //if (isExecuted)
                    //{

                    //    isExecuted = bll.Update<DDCI_INFO>(new List<DDCI_INFO>() { ActiveEntity });
                    //    if (isExecuted)
                    //    {
                    //        ShowInformationMessage("Records saved successfully");
                    //    }
                    //}
                    //#endregion
                    break;

                case OperationMode.Delete:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
            ActionMode = OperationMode.AddNew;
            //CIReferenceDataSource = bll.GetCIReferenceNumber().ToDataTable<V_CI_REFERENCE_NUMBER>().DefaultView;
            ChangeRights();
            Reload = true;
            CloseAction();
        }
        public CopyCIReferenceViewModel(UserInformation userInformation, WPF.MDI.MdiChild mdiChild, DDCI_INFO oldActiveEntity,
                                        OperationMode operationMode)
        {
            bll = new FeasibleReportAndCostSheet(userInformation);

            EnquiryReceivedOn = bll.ServerDateTime();

            OldCIReferenceDataSource  = bll.GetCIReferenceNumber().ToDataTable <V_CI_REFERENCE_NUMBER>().DefaultView;
            CIReferenceZoneDataSource = bll.GetZoneDetails().ToDataTable <CI_REFERENCE_ZONE>().DefaultView;

            OldActiveEntity = oldActiveEntity;

            if (!OldActiveEntity.IsNotNullOrEmpty())
            {
                OldActiveEntity = new DDCI_INFO();
            }
            EntityPrimaryKey = oldActiveEntity.IDPK;

            #region DropdownColumns Settins
            CiReferenceZoneDropDownItems = new ObservableCollection <DropdownColumns>()
            {
                new DropdownColumns()
                {
                    ColumnName = "CODE", ColumnDesc = "Zone Code", ColumnWidth = "25*"
                },
                new DropdownColumns()
                {
                    ColumnName = "DESCRIPTION", ColumnDesc = "Zone", ColumnWidth = "75*"
                }
            };

            OldCIReferenceDropDownItems = new ObservableCollection <DropdownColumns>()
            {
                new DropdownColumns()
                {
                    ColumnName = "CI_REFERENCE", ColumnDesc = "CI Reference", ColumnWidth = "90"
                },
                new DropdownColumns()
                {
                    ColumnName = "FRCS_DATE", ColumnDesc = "FRCS Date", ColumnWidth = "80"
                },
                new DropdownColumns()
                {
                    ColumnName = "CUST_DWG_NO", ColumnDesc = "Drawing No.", ColumnWidth = "100"
                },
                new DropdownColumns()
                {
                    ColumnName = "CUST_CODE", ColumnDesc = "Customer Code", ColumnWidth = "100"
                },
                new DropdownColumns()
                {
                    ColumnName = "FINISH_CODE", ColumnDesc = "Finish Code", ColumnWidth = "80"
                },
                new DropdownColumns()
                {
                    ColumnName = "CUST_DWG_NO_ISSUE", ColumnDesc = "Customer Drawing Issue No.", ColumnWidth = "175"
                },
                new DropdownColumns()
                {
                    ColumnName = "CUST_STD_DATE", ColumnDesc = "Customer STD Date ", ColumnWidth = "150"
                }
            };

            #endregion

            this.ciReferenceEndEditCommand = new DelegateCommand(this.ciReferenceEndEdit);
            this.oldReferenceSelectedItemChangedCommand = new DelegateCommand(this.OldCIReferenceChanged);

            this.enquiryReceivedOnChangedCommand = new DelegateCommand(this.EnquiryReceivedOnChanged);
            this.saveCommand = new DelegateCommand(this.SaveSubmitCommand);
            this.ciReferenceZoneSelectedItemChangedCommand = new DelegateCommand(this.CIReferenceZoneChanged);

            ActionPermission        = bll.GetUserRights("CIReferenceCopy");
            ActionPermission.AddNew = true;
            ActionPermission.Edit   = true;
            ActionPermission.Save   = true;
            ActionPermission.Close  = true;
            ActionPermission.Print  = true;

            ActionMode = operationMode;
        }