protected void imgSampleDetailsEidt_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                ImageButton imgbtn = (ImageButton)sender;
                GridViewRow row    = (GridViewRow)imgbtn.NamingContainer;

                Label            lblID = (Label)grdSampleDetails.Rows[row.RowIndex].FindControl("lblID");
                int              Id    = Convert.ToInt16(lblID.Text);
                LC_SampleDetails _SD   = _SampleDetailsbll.GetSDetailsById(Id);
                if (_SD != null)
                {
                    HidId.Value                  = _SD.SampleId.ToString();
                    ddlBuyer.SelectedValue       = _SD.Buyer_ID.ToString();
                    ddlFactoryMame.SelectedValue = _SD.FactoryId.ToString();
                    txtPreOrderNo.Text           = _SD.Pre_OrderNo;
                    txtSampleDate.Text           = _SD.SampleDate.ToString();
                    txtSampleSpecification.Text  = _SD.SampleSpecification;
                    byte[] picUp = SetImage();
                    picUp                     = _SD.Sample_Photo;
                    Session["picUp"]          = picUp;
                    txt1stSampleSentDate.Text = _SD.First_SampleSentDate.ToString();
                }
                btnSubmit.Text = "Update";
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 internal int Insert(LC_SampleDetails _ObjSampleDetails)
 {
     try
     {
         _Context.LC_SampleDetails.AddObject(_ObjSampleDetails);
         _Context.SaveChanges();
         return(1);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        protected void imgSampleDetailsEidt_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                ImageButton imgbtn = (ImageButton)sender;
                GridViewRow row    = (GridViewRow)imgbtn.NamingContainer;

                Label            lblID = (Label)grdSampleDetails.Rows[row.RowIndex].FindControl("lblID");
                int              Id    = Convert.ToInt16(lblID.Text);
                LC_SampleDetails _SD   = _SampleDetailsbll.GetSDetailsById(Id);
                if (_SD != null)
                {
                    HidId.Value                  = _SD.SampleId.ToString();
                    ddlBuyer.SelectedValue       = _SD.Buyer_ID.ToString();
                    ddlFactoryMame.SelectedValue = _SD.FactoryId.ToString();
                    txtPreOrderNo.Text           = _SD.Pre_OrderNo;
                    txtSampleDate.Text           = _SD.SampleDate.ToString();
                    txtSampleSpecification.Text  = _SD.SampleSpecification;
                    txt1stSampleSentDate.Text    = _SD.First_SampleSentDate.ToString();
                    txtModiReceiveDate.Text      = _SD.Modi_ReceiveDate.ToString();

                    txtCounterSampleSendDate.Text = _SD.Counter_SampleSend_Date.ToString();
                    txtSizeSetDate.Text           = _SD.SizeSet_Date.ToString();
                    txtCostingSendDate.Text       = _SD.Costing_SendDate.ToString();

                    txtProductionApprovedDate.Text = _SD.Production_ApprovedDate.ToString();
                    txtBVTestSubmitDate.Text       = _SD.BV_TestSubmitDate.ToString();
                    txtBVTestReleaseDate.Text      = _SD.BV_TestReleaseDate.ToString();

                    txtSealingSampleSubmitDate.Text    = _SD.SealingSample_SubmitDate.ToString();
                    txtSealingSampleReleaseDate.Text   = _SD.SealingSample_RelaseDate.ToString();
                    txtShipmentSampleSendDate.Text     = _SD.ShipmentSample_SendDate.ToString();
                    txtShipmentSampleApprovedDate.Text = _SD.ShipmentSample_ApprovedDate.ToString();
                }
                DivUpdate.Visible = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        internal int Update(LC_SampleDetails _ObjSampleDetails)
        {
            try
            {
                LC_SampleDetails _SampleDetails = _Context.LC_SampleDetails.FirstOrDefault(x => x.SampleId == _ObjSampleDetails.SampleId);
                _SampleDetails.Buyer_ID             = _ObjSampleDetails.Buyer_ID;
                _SampleDetails.FactoryId            = _ObjSampleDetails.FactoryId;
                _SampleDetails.SampleDate           = _ObjSampleDetails.SampleDate;
                _SampleDetails.Pre_OrderNo          = _ObjSampleDetails.Pre_OrderNo;
                _SampleDetails.SampleSpecification  = _ObjSampleDetails.SampleSpecification;
                _SampleDetails.First_SampleSentDate = _ObjSampleDetails.First_SampleSentDate;
                _SampleDetails.Sample_Photo         = _ObjSampleDetails.Sample_Photo;

                _SampleDetails.EditDate = DateTime.Now;
                _SampleDetails.EditUser = _ObjSampleDetails.EditUser;
                _Context.SaveChanges();
                return(1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        internal int SampleUpdate(LC_SampleDetails _ObjSampleDetails)
        {
            try
            {
                LC_SampleDetails _SampleDetails = _Context.LC_SampleDetails.FirstOrDefault(x => x.SampleId == _ObjSampleDetails.SampleId);
                _SampleDetails.Buyer_ID             = _ObjSampleDetails.Buyer_ID;
                _SampleDetails.FactoryId            = _ObjSampleDetails.FactoryId;
                _SampleDetails.SampleDate           = _ObjSampleDetails.SampleDate;
                _SampleDetails.Pre_OrderNo          = _ObjSampleDetails.Pre_OrderNo;
                _SampleDetails.SampleSpecification  = _ObjSampleDetails.SampleSpecification;
                _SampleDetails.First_SampleSentDate = _ObjSampleDetails.First_SampleSentDate;

                _SampleDetails.Modi_ReceiveDate            = _ObjSampleDetails.Modi_ReceiveDate;
                _SampleDetails.Modi_Status                 = _ObjSampleDetails.Modi_Status;
                _SampleDetails.Counter_SampleSend_Date     = _ObjSampleDetails.Counter_SampleSend_Date;
                _SampleDetails.SizeSet_Date                = _ObjSampleDetails.SizeSet_Date;
                _SampleDetails.Costing_SendDate            = _ObjSampleDetails.Costing_SendDate;
                _SampleDetails.Production_ApprovedDate     = _ObjSampleDetails.Production_ApprovedDate;
                _SampleDetails.BV_TestSubmitDate           = _ObjSampleDetails.BV_TestSubmitDate;
                _SampleDetails.BV_TestReleaseDate          = _ObjSampleDetails.BV_TestReleaseDate;
                _SampleDetails.SealingSample_SubmitDate    = _ObjSampleDetails.SealingSample_SubmitDate;
                _SampleDetails.SealingSample_RelaseDate    = _ObjSampleDetails.SealingSample_RelaseDate;
                _SampleDetails.ShipmentSample_SendDate     = _ObjSampleDetails.ShipmentSample_SendDate;
                _SampleDetails.ShipmentSample_ApprovedDate = _ObjSampleDetails.ShipmentSample_ApprovedDate;
                _SampleDetails.Sample_Status               = _ObjSampleDetails.Sample_Status;

                _SampleDetails.EditDate = DateTime.Now;
                _SampleDetails.EditUser = _ObjSampleDetails.EditUser;
                _Context.SaveChanges();
                return(1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                byte[] res = Session["picUp"] as byte[];
                byte[] pic = SetImage();

                DateTime?SampleDate = null;

                LC_SampleDetails _ObjSampleDetails = new LC_SampleDetails();

                _ObjSampleDetails.Buyer_ID    = Convert.ToInt32(ddlBuyer.SelectedValue);
                _ObjSampleDetails.FactoryId   = Convert.ToInt32(ddlFactoryMame.SelectedValue);
                _ObjSampleDetails.Pre_OrderNo = txtPreOrderNo.Text;
                if (txtSampleDate.Text == "")
                {
                    _ObjSampleDetails.SampleDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.SampleDate = Convert.ToDateTime(txtSampleDate.Text);
                }
                _ObjSampleDetails.SampleSpecification = txtSampleSpecification.Text;
                _ObjSampleDetails.Pre_OrderNo         = txtPreOrderNo.Text;
                if (txt1stSampleSentDate.Text == "")
                {
                    _ObjSampleDetails.First_SampleSentDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.First_SampleSentDate = Convert.ToDateTime(txt1stSampleSentDate.Text);
                }

                //if (FileUpload1.FileName == null)
                //{
                if (_ObjSampleDetails.Sample_Photo == res)
                {
                    _ObjSampleDetails.Sample_Photo = pic;
                }
                else
                {
                    _ObjSampleDetails.Sample_Photo = res;
                }
                //}
                //else
                //{
                //    _ObjSampleDetails.Sample_Photo = pic;
                //}
                _ObjSampleDetails.CreateDate = DateTime.Now;
                _ObjSampleDetails.CreateUser = (((SessionUser)Session["SessionUser"]).UserId);
                _ObjSampleDetails.OCode      = Convert.ToString(((SessionUser)Session["SessionUser"]).OCode);

                if (btnSubmit.Text != "Update")
                {
                    int result = _SampleDetailsbll.Insert(_ObjSampleDetails);
                    if (result == 1)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Saved Successfully')", true);
                    }
                }
                else
                {
                    _ObjSampleDetails.EditDate = DateTime.Now;
                    _ObjSampleDetails.EditUser = (((SessionUser)Session["SessionUser"]).UserId);;
                    _ObjSampleDetails.SampleId = Convert.ToInt16(HidId.Value);
                    int result = _SampleDetailsbll.Update(_ObjSampleDetails);
                    if (result == 1)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Updated Successfully')", true);
                    }
                }
                ClearUi();
                ShowSampleDetailGrid();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                LC_SampleDetails _ObjSampleDetails = new LC_SampleDetails();

                DateTime?SampleDate = null;

                _ObjSampleDetails.Buyer_ID    = Convert.ToInt32(ddlBuyer.SelectedValue);
                _ObjSampleDetails.FactoryId   = Convert.ToInt32(ddlFactoryMame.SelectedValue);
                _ObjSampleDetails.Pre_OrderNo = txtPreOrderNo.Text;
                if (txtSampleDate.Text == "")
                {
                    _ObjSampleDetails.SampleDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.SampleDate = Convert.ToDateTime(txtSampleDate.Text);
                }
                _ObjSampleDetails.SampleSpecification = txtSampleSpecification.Text;
                _ObjSampleDetails.Pre_OrderNo         = txtPreOrderNo.Text;
                if (txt1stSampleSentDate.Text == "")
                {
                    _ObjSampleDetails.First_SampleSentDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.First_SampleSentDate = Convert.ToDateTime(txt1stSampleSentDate.Text);
                }

                if (txtModiReceiveDate.Text == "")
                {
                    _ObjSampleDetails.Modi_ReceiveDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.Modi_ReceiveDate = Convert.ToDateTime(txtModiReceiveDate.Text);
                }

                _ObjSampleDetails.Modi_Status = "True";

                if (txtCounterSampleSendDate.Text == "")
                {
                    _ObjSampleDetails.Counter_SampleSend_Date = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.Counter_SampleSend_Date = Convert.ToDateTime(txtCounterSampleSendDate.Text);
                }

                if (txtSizeSetDate.Text == "")
                {
                    _ObjSampleDetails.SizeSet_Date = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.SizeSet_Date = Convert.ToDateTime(txtSizeSetDate.Text);
                }

                if (txtCostingSendDate.Text == "")
                {
                    _ObjSampleDetails.Costing_SendDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.Costing_SendDate = Convert.ToDateTime(txtCostingSendDate.Text);
                }

                if (txtProductionApprovedDate.Text == "")
                {
                    _ObjSampleDetails.Production_ApprovedDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.Production_ApprovedDate = Convert.ToDateTime(txtProductionApprovedDate.Text);
                }

                if (txtBVTestSubmitDate.Text == "")
                {
                    _ObjSampleDetails.BV_TestSubmitDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.BV_TestSubmitDate = Convert.ToDateTime(txtBVTestSubmitDate.Text);
                }

                if (txtBVTestReleaseDate.Text == "")
                {
                    _ObjSampleDetails.BV_TestReleaseDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.BV_TestReleaseDate = Convert.ToDateTime(txtBVTestReleaseDate.Text);
                }

                if (txtSealingSampleSubmitDate.Text == "")
                {
                    _ObjSampleDetails.SealingSample_SubmitDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.SealingSample_SubmitDate = Convert.ToDateTime(txtSealingSampleSubmitDate.Text);
                }

                if (txtSealingSampleReleaseDate.Text == "")
                {
                    _ObjSampleDetails.SealingSample_RelaseDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.SealingSample_RelaseDate = Convert.ToDateTime(txtSealingSampleReleaseDate.Text);
                }

                if (txtShipmentSampleSendDate.Text == "")
                {
                    _ObjSampleDetails.ShipmentSample_SendDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.ShipmentSample_SendDate = Convert.ToDateTime(txtShipmentSampleSendDate.Text);
                }

                if (txtShipmentSampleApprovedDate.Text == "")
                {
                    _ObjSampleDetails.ShipmentSample_ApprovedDate = SampleDate;
                }
                else
                {
                    _ObjSampleDetails.ShipmentSample_ApprovedDate = Convert.ToDateTime(txtShipmentSampleApprovedDate.Text);
                }


                if (rdbApproved.Checked == true)
                {
                    _ObjSampleDetails.Sample_Status = "Approved";
                }
                else
                {
                    _ObjSampleDetails.Sample_Status = "Decline";
                }
                _ObjSampleDetails.EditDate = DateTime.Now;
                _ObjSampleDetails.EditUser = (((SessionUser)Session["SessionUser"]).UserId);
                _ObjSampleDetails.OCode    = Convert.ToString(((SessionUser)Session["SessionUser"]).OCode);

                if (btnSubmit.Text == "Submit")
                {
                    _ObjSampleDetails.SampleId = Convert.ToInt16(HidId.Value);
                    int result = _SampleDetailsbll.SampleUpdate(_ObjSampleDetails);
                    if (result == 1)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Updated Successfully')", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Data Save failure')", true);
                }
                ClearUi();
                DivUpdate.Visible = false;
                ShowSampleDetailGrid();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 internal int SampleUpdate(LC_SampleDetails _ObjSampleDetails)
 {
     return(_SampleDetailsdal.SampleUpdate(_ObjSampleDetails));
 }
 internal int Insert(LC_SampleDetails _ObjSampleDetails)
 {
     return(_SampleDetailsdal.Insert(_ObjSampleDetails));
 }