protected void pcInteruptFault_WindowCallback(object source, PopupWindowCallbackArgs e)
 {
     // loadFaultDefault();
     GVDataAttachment.DataSource = Session["dtAttachment"];
     GVDataAttachment.DataBind();
     PopUpAttachMent.ShowOnPageLoad = false;
 }
        protected void IdBtndelete_Click(object sender, EventArgs e)
        {
            ASPxButton btn = sender as ASPxButton;
            GridViewDataItemTemplateContainer container = btn.NamingContainer as GridViewDataItemTemplateContainer;
            var Rowindex   = container.VisibleIndex;
            int ValueRowId = int.Parse(GVDataAttachment.GetRowValues(Rowindex, "Id").ToString());
            //var Data = Session["DataDetail"];
            var       oldattachImage = Session["dtAttachment"] as List <ProductionFaultReleaseAttachmentModel>;
            DataTable Datax          = Session["dtAttachment"] as DataTable;

            //List<DocumentAttachment> ListAttachFile = new List<DocumentAttachment>();
            //List<DataRow> list = Datax.AsEnumerable().ToList();
            //int Id = int.Parse(Datax.Rows[0].ItemArray[0].ToString());
            for (int i = 0; i < Datax.Rows.Count; i++)
            {
                int Id = int.Parse(Datax.Rows[i].ItemArray[0].ToString());
                if (Id == ValueRowId)
                {
                    DataRow dr = Datax.Rows[i];
                    dr.Delete();
                    // dr.AcceptChanges();
                }
            }


            DataTable DataNew = new DataTable();

            DataNew = Datax;
            GVDataAttachment.DataSource = DataNew;
            Session["dtAttachment"]     = DataNew;
            GVDataAttachment.DataBind();
        }
        //binding & set default form Fault
        private void loadFaultDefaultEdit(int id)
        {
            Session["DtAttachmentEdit"] = null;
            HiddenText["Edit"]          = "1";
            HiddenText["IdFault"]       = id;
            var DataLoad = FaultRepository.GetFaultRecordById(id);

            currentdate.Date = DateTime.Now;
            //GVDataAttachment.DataSource = Session["dtAttachment"];
            //GVDataAttachment.DataBind();
            CSTypeValue.Text     = DataLoad[0].CSType.ToString();
            cbStation.Text       = DataLoad[0].StationName.ToString();
            cbStation.ReadOnly   = true;
            cbStamp.Text         = DataLoad[0].StamperName;
            tbRemark.Text        = DataLoad[0].Remarks;
            cbQG.Text            = DataLoad[0].QualityGateName.ToString();
            cbQG.ReadOnly        = true;
            cbFINNumber.Text     = DataLoad[0].FINNumber.ToString();
            cbFINNumber.ReadOnly = true;

            cbPartProces.Text   = DataLoad[0].FaultPartProcessDesc.ToString();
            cbFaultDesc.Text    = DataLoad[0].FaultDescriptionText;
            cbFaultRelated.Text = DataLoad[0].FaultRelatedTypeDesc;
            cbPriority.Text     = DataLoad[0].Priority.ToString();
            cbInspector.Text    = DataLoad[0].InspectorName;
            cbStamp.Text        = DataLoad[0].StamperName;
            cbRecti.Text        = DataLoad[0].IsSentToRectification.ToString();
            tbNCP.Text          = DataLoad[0].NCP;
            tbRemark.Text       = DataLoad[0].Remarks;

            //set TextBox Line
            //string line = GetLine(Convert.ToInt32(cbFINNumber.Value));
            tbLine.Text = DataLoad[0].ProductionLineName;

            //set textBox Assembly Section
            //string section = GetSection(Convert.ToInt32(cbStation.Value));
            tbAssemblySection.Text = DataLoad[0].AssemblySectionName;

            //set textBox Fault Classification
            //string classification = GetClassification(Convert.ToInt32(cbFaultDesc.Value));
            tbClassification.Text = DataLoad[0].FaultClassDescription;

            //set comboBox CGIS
            cbCGISx.Text            = DataLoad[0].CGISNo;
            HiddenText["FINNumber"] = cbFINNumberx.Text == "1" ? "-Select-" : cbFINNumberx.Text;
            if (cbFINNumberx.Text == "1")
            {
                cbFINNumberx.Text = "-Select-";
            }
            else
            {
                cbFINNumberx.Text = DataLoad[0].FINNumber;
            }
            var faults = FaultRepository.GetAttachMentViewEdit(id);

            Session["DtAttachmentEdit"] = faults;
            Session["dtAttachment"]     = ConvertListToDataTable(faults);
            GVDataAttachment.DataSource = faults;
            GVDataAttachment.DataBind();
        }
        protected void PopUpAttachMent_WindowCallback(object source, PopupWindowCallbackArgs e)
        {
            pcInteruptFault.ShowOnPageLoad = false;

            PopUpAttachMent.ShowOnPageLoad = false;
            pcInteruptFault.ShowOnPageLoad = true;
            GVDataAttachment.DataSource    = Session["dtAttachment"];
            GVDataAttachment.DataBind();
        }
        //binding & set default form Fault
        private void loadFaultDefault()
        {
            HiddenText["Edit"]          = "0";
            Session["DtAttachmentEdit"] = null;
            Session["dtAttachment"]     = null;
            GVDataAttachment.DataSource = null;
            GVDataAttachment.DataBind();
            currentdate.Date        = DateTime.Now;
            cbStation.SelectedIndex = 0;
            cbQG.SelectedIndex      = 0;
            cbFINNumber.Value       = 1;
            CSTypeValue.NullText    = "-Select-";

            cbPartProces.SelectedIndex   = 0;
            cbFaultDesc.SelectedIndex    = 0;
            cbFaultRelated.SelectedIndex = 0;
            cbPriority.SelectedIndex     = 0;
            cbInspector.SelectedIndex    = 0;
            cbStamp.SelectedIndex        = 0;
            cbRecti.SelectedIndex        = 0;
            tbNCP.Text    = "";
            tbRemark.Text = "";

            //set TextBox Line
            string line = GetLine(Convert.ToInt32(cbFINNumber.Value));

            tbLine.Text = line;

            //set textBox Assembly Section
            string section = GetSection(Convert.ToInt32(cbStation.Value));

            tbAssemblySection.Text = section;

            //set textBox Fault Classification
            string classification = GetClassification(Convert.ToInt32(cbFaultDesc.Value));

            tbClassification.Text = classification;

            //set comboBox CGIS
            Session["StationId"] = cbStation.Value;
            Session["HistoryId"] = cbFINNumber.Value;
            cbCGIS.DataSource    = sdsCgis;
            cbCGIS.DataBind();
            cbCGIS.SelectedIndex = 0;
            //HiddenText["FINNumber"] = cbFINNumber.Text == "1" ? "-Select-" : cbFINNumber.Text;
            if (Session["FINNumber"] != null)
            {
                cbFINNumber.Text = Session["FINNumber"].ToString();
            }
            if (Session["CSType"] != null)
            {
                CSTypeValue.Value = Session["CSType"].ToString();
            }
            GVDataAttachment.DataSource = "";
            //CSTypeValue.Text = "-Select-";
        }
        public ProductionReleaseFaultModel faultRecord()
        {
            var finnumber = "";

            if (CSTypeValue.Text.ToString() != "-Select-")
            {
                int csType = CSTypeValue.Text.ToString() == "" ? 0 : int.Parse(CSTypeValue.SelectedItem.Value.ToString());
            }
            else
            {
                FaultRecord FaultInput = new FaultRecord();
                //FaultInput.CSType = CSTypeValue.Text == "" ? 0 : int.Parse(CSTypeValue.SelectedItem.Value.ToString());
                FaultInput.Remarks = "MandatoryEmpty";
                ProductionReleaseFaultModel InsertFaultRecordFault = new ProductionReleaseFaultModel();
                {
                    InsertFaultRecordFault.FaultRecordModels = FaultInput;
                };
                return(InsertFaultRecordFault);
            }
            var ncp = tbNCP.Text;
            // int productionHistoriesId = cbFINNumber.Value == null ? 0 : Convert.ToInt32(cbFINNumber.SelectedItem.Text);
            int          productionHistoriesId = 0;
            var          faultNumber           = "32054";
            int          QGate        = Convert.ToInt32(cbQG.Value);
            int          station      = Convert.ToInt32(cbStation.Value);
            ListEditItem selectedItem = cbFINNumber.SelectedItem;

            if (cbFINNumber.Text.ToString() == "-Select-")
            {
                FaultRecord FaultInputfailed = new FaultRecord();
                FaultInputfailed.CSType  = CSTypeValue.Text == "" ? 0 : int.Parse(CSTypeValue.SelectedItem.Value.ToString());
                FaultInputfailed.Remarks = "MandatoryEmpty2";
                ProductionReleaseFaultModel InsertFaultRecordFaultfailed = new ProductionReleaseFaultModel();
                {
                    InsertFaultRecordFaultfailed.FaultRecordModels = FaultInputfailed;
                };
                return(InsertFaultRecordFaultfailed);
            }
            else
            {
                // finnumber = cbFINNumber.Text == "1" ? Session["FINNumber"].ToString() : cbFINNumber.Text;
                finnumber = selectedItem.GetValue("FINNumber").ToString();
            }

            var tempAssemblySection = ProductionRepository.GetAssemblySection(station);
            int assemblySectionId   = tempAssemblySection.Id;

            var tempProductionLine = ProductionRepository.GetLineByProductionId(productionHistoriesId);
            int productionLineId   = tempProductionLine.Id;

            var cgisId       = Convert.ToInt32(cbCGIS.Value);
            int priority     = Convert.ToInt32(cbPriority.Value);
            int partProces   = Convert.ToInt32(cbPartProces.Value);
            int faultRelated = Convert.ToInt32(cbFaultRelated.Value);
            int faultDescId;

            if (int.TryParse(cbFaultDesc.Value.ToString(), out faultDescId))
            {
                faultDescId = Convert.ToInt32(cbFaultDesc.Value);
            }
            else
            {
                faultDescId = ProductionRepository.InputNonStandard(cbFaultDesc.Value.ToString());
            }
            var faultDescText = cbFaultDesc.Text;
            int inspectorId   = Convert.ToInt32(cbInspector.Value);
            var inspectorName = cbInspector.SelectedItem;
            int stampId       = Convert.ToInt32(cbStamp.Value);
            // var stampName = cbStamp.SelectedItem;
            var  stampName = "";
            var  remark    = tbRemark.Text;
            bool recti     = Convert.ToBoolean(cbRecti.Value.ToInt32());

            FaultRecord DataFault = new FaultRecord();

            DataFault.CSType = CSTypeValue.Text == "-Select-" ? 0 : int.Parse(CSTypeValue.SelectedItem.Value.ToString());
            DataFault.NCP    = ncp;
            DataFault.ProductionHistoriesId = productionHistoriesId;
            DataFault.FaultNumber           = faultNumber;
            DataFault.QualityGateId         = QGate;
            DataFault.AssemblySectionId     = assemblySectionId;
            DataFault.ProductionLinesId     = productionLineId;
            DataFault.StationId             = station;
            DataFault.FINNumber             = finnumber.ToString();
            DataFault.CGISId                = cgisId;
            DataFault.Priority              = priority;
            DataFault.FaultPartProcessId    = partProces;
            DataFault.FaultRelatedTypeId    = faultRelated;
            DataFault.FaultDescriptionId    = faultDescId;
            DataFault.FaultDescriptionText  = faultDescText;
            DataFault.InspectorUserId       = inspectorId == null ? 0 : inspectorId;
            DataFault.InspectorName         = inspectorName.ToString();
            DataFault.StamperUserID         = stampId;
            DataFault.StamperName           = stampName.ToString();
            DataFault.Remarks               = remark;
            DataFault.IsSentToRectification = recti;
            DataFault.UserAuth              = "";


            var SumRowData = GVDataAttachment.VisibleRowCount;
            List <DocumentAttachment> ListAttachFile = new List <DocumentAttachment>();

            for (int i = 0; i < SumRowData; i++)
            {
                DocumentAttachment AttachFile = new DocumentAttachment();
                AttachFile.FileName = GVDataAttachment.GetRowValues(i, "FileName").ToString();
                AttachFile.FilePath = GVDataAttachment.GetRowValues(i, "FileLocation").ToString();
                ListAttachFile.Add(AttachFile);
            }

            ProductionReleaseFaultModel InsertFaultRecord = new ProductionReleaseFaultModel();

            {
                InsertFaultRecord.FaultRecordModels = DataFault;
                InsertFaultRecord.AttachmentModels  = ListAttachFile;
            };
            return(InsertFaultRecord);
        }
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            if (HiddenText["Edit"].ToString() == "0")
            {
                var fault = faultRecord();

                if (fault.FaultRecordModels.Remarks != "MandatoryEmpty")
                {
                    if (fault.FaultRecordModels.Remarks != "MandatoryEmpty2")
                    {
                        var GetIdFault = FaultRepository.InsertFaultRecordReleaseDynamic(fault.FaultRecordModels);

                        for (int x = 0; x < fault.AttachmentModels.Count(); x++)
                        {
                            var id = cbFINNumber.Text.Split('/')[1].Trim();
                            FaultRepository.InsertAttachMent(fault.AttachmentModels[x].FileName, fault.AttachmentModels[x].FilePath, id, GetIdFault);
                        }
                        //add to fault record

                        //close popUpControl Fault
                        pcInteruptFault.ShowOnPageLoad = false;
                        //binding again grid Fault
                        gridFault.DataBind();
                        // detailCondition.ImageUrl = FaultRepository.IsHaveFault(_historyId) ? urlImgNotifRed : urlImgNotifGreen;
                        //}
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage2", @"alert('Please Fill FinNumber');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage4", @"alert('Please Fill CSType');", true);
                }

                Response.Redirect("../Production/ProductionReleaseFault.aspx");
            }
            else
            {
                var model   = new FaultRecord();
                int IdFault = int.Parse(HiddenText["IdFault"].ToString());
                model.FaultRecordId      = IdFault;
                model.FaultStatus        = faultStatus.Text == "" ? 0 : int.Parse(faultStatus.SelectedItem.Value.ToString());
                model.Remarks            = tbRemark.Text.ToString();
                model.Priority           = cbPriority.SelectedItem == null ? 0 : int.Parse(cbPriority.Value.ToString());
                model.FaultDescriptionId = cbFaultDesc.SelectedItem == null ? 0 : int.Parse(cbFaultDesc.Value.ToString());
                model.FaultRelatedTypeId = cbFaultRelated.SelectedItem == null ? 0 : int.Parse(cbFaultRelated.Value.ToString());
                FaultRepository.UpdateFaultRecord(model);
                FaultRepository.Delete(IdFault);
                var SumRowData = GVDataAttachment.VisibleRowCount;
                List <DocumentAttachment> ListAttachFile = new List <DocumentAttachment>();
                for (int i = 0; i < SumRowData; i++)
                {
                    DocumentAttachment AttachFile = new DocumentAttachment();
                    AttachFile.FileName = GVDataAttachment.GetRowValues(i, "FileName").ToString();
                    AttachFile.FilePath = GVDataAttachment.GetRowValues(i, "FileLocation").ToString();
                    ListAttachFile.Add(AttachFile);
                }


                for (int x = 0; x < ListAttachFile.Count(); x++)
                {
                    var Fin = cbFINNumber.Text;
                    FaultRepository.InsertAttachMent(ListAttachFile[x].FileName, ListAttachFile[x].FilePath, Fin, IdFault);
                }
                pcInteruptFault.ShowOnPageLoad  = false;
                pcInteruptFaultx.ShowOnPageLoad = false;
                Response.Redirect("../Production/ProductionReleaseFault.aspx");
            }
        }