public ActionResult NewWorkorder(ssmtbl_WorkorderModel objWoMod)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string result = objWoData.InsertWorkorder(objWoMod);
                    if (result == "Workorder Created Successfully!")
                    {
                        ModelState.Clear();
                        objWoMod                     = new ssmtbl_WorkorderModel();
                        objWoMod.WorkorderNo         = objWoData.GetMaxWorkorderNo();
                        objWoMod.DateOfIssue         = DateTime.Now;
                        objWoMod.TargetDate          = DateTime.Now;
                        objWoMod.ProductionStartDate = DateTime.Now;
                        @ViewBag.HideClass           = "alert alert-success";
                        @ViewBag.Message             = result;
                    }
                    else
                    {
                        @ViewBag.HideClass = "alert alert-danger";
                        @ViewBag.Message   = result;
                    }
                }
            }
            catch (Exception ex)
            {
                Global.ErrorHandlerClass.LogError(ex);
                @ViewBag.HideClass = "alert alert-danger";
                @ViewBag.Message   = "Workorder Not Saved!";
            }


            return(View(objWoMod));
        }
        public List <ssmtbl_WorkorderModel> GetWoDataByPO(string po = "")
        {
            List <ssmtbl_WorkorderModel> objWoList = new List <ssmtbl_WorkorderModel>();

            try
            {
                var connection = gConnection.Connection();
                connection.Open();
                string     sqlstr = "ssmsp_getInquiryfrompoid";
                SqlCommand cmd    = new SqlCommand(sqlstr, connection);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ponumber", po);
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    ssmtbl_WorkorderModel objtemp = new ssmtbl_WorkorderModel();
                    objtemp.CutWeight   = (sdr["cutweight"].ToString());
                    objtemp.HeatCode    = (sdr["FeasibilityHeattreatment"].ToString());
                    objtemp.ColorCode   = (sdr["ColorCode"].ToString());
                    objtemp.RawMaterial = (sdr["RawMaterial"].ToString());
                    objtemp.Section     = (sdr["Section"].ToString());
                    objtemp.PoRM        = (sdr["PORM"].ToString());
                    objtemp.PoSection   = (sdr["Section"].ToString());
                    objWoList.Add(objtemp);
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }
            return(objWoList);
        }
        public List <ssmtbl_WorkorderModel> GetAllWorkorder()
        {
            List <ssmtbl_WorkorderModel> objWoList = new List <ssmtbl_WorkorderModel>();

            try
            {
                var connection = gConnection.Connection();
                connection.Open();
                string     sqlstr = "ssmsp_Get_AllWorkorder";
                SqlCommand cmd    = new SqlCommand(sqlstr, connection);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Action", "Select");
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    ssmtbl_WorkorderModel objtemp = new ssmtbl_WorkorderModel();
                    objtemp.WorkorderID = Convert.ToInt32(sdr["WorkorderID"].ToString());
                    objtemp.WorkorderNo = sdr["WorkorderNo"].ToString();
                    objtemp.PlanQty     = Convert.ToDecimal(sdr["PlanQty"].ToString());
                    objtemp.TargetDate  = Convert.ToDateTime(sdr["TargetDate"].ToString());
                    objtemp.CreatedDate = Convert.ToDateTime(sdr["CreatedDate"].ToString());
                    objWoList.Add(objtemp);
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }

            return(objWoList);
        }
        public List <ssmtbl_WorkorderModel> GetWorkorderApprovalList(string woStatus)
        {
            List <ssmtbl_WorkorderModel> objList = new List <ssmtbl_WorkorderModel>();

            try
            {
                string sqlstr     = "uspRMApproval";
                var    connection = gConnection.Connection();
                connection.Open();
                SqlCommand cmd = new SqlCommand(sqlstr, connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Action", "SelectWoList");
                cmd.Parameters.AddWithValue("@WorkorderStatus", woStatus.Trim());
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    ssmtbl_WorkorderModel objModel = new ssmtbl_WorkorderModel();

                    objModel.PartName    = sdr["PartName"].ToString();
                    objModel.WorkorderNo = sdr["ReqNo"].ToString();
                    objModel.PartNo      = sdr["PartNO"].ToString();
                    objModel.Type        = sdr["Type"].ToString();
                    objModel.RfqID       = sdr["RfqID"].ToString();
                    objModel.RawMaterial = sdr["ReqTypeMaterial"].ToString();
                    objList.Add(objModel);
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }
            return(objList);
        }
        public List <ssmtbl_WorkorderModel> GetWorkorderApprovalList(string dieStatus)
        {
            List <ssmtbl_WorkorderModel> objList = new List <ssmtbl_WorkorderModel>();

            try
            {
                string sqlstr     = "uspDieApproval";
                var    connection = gConnection.Connection();
                connection.Open();
                SqlCommand cmd = new SqlCommand(sqlstr, connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Action", "SelectDieList");
                cmd.Parameters.AddWithValue("@Status", dieStatus.Trim());
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    ssmtbl_WorkorderModel objModel = new ssmtbl_WorkorderModel();

                    objModel.DieNumber        = sdr["DieNumber"].ToString();
                    objModel.WorkorderNo      = sdr["WorkorderNumber"].ToString();
                    objModel.DieReqDate       = Convert.ToDateTime(sdr["ReqDate"].ToString());
                    objModel.DieRequisitionID = Convert.ToInt32(sdr["DieRequisitionID"].ToString());
                    objList.Add(objModel);
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }
            return(objList);
        }
        public List <ssmtbl_WorkorderModel> GetWoDataByPOID(string poID)
        {
            List <ssmtbl_WorkorderModel> objWoList = new List <ssmtbl_WorkorderModel>();

            try
            {
                var connection = gConnection.Connection();
                connection.Open();
                string     sqlstr = "ssmsp_getInquiryfrompoid";
                SqlCommand cmd    = new SqlCommand(sqlstr, connection);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@POID", Convert.ToInt32(poID));
                SqlDataReader sdr = cmd.ExecuteReader();
                //SqlDataAdapter da = new SqlDataAdapter(cmd);
                //DataTable dt = new DataTable();
                //da.Fill(dt);
                while (sdr.Read())
                {
                    ssmtbl_WorkorderModel objtemp = new ssmtbl_WorkorderModel();
                    objtemp.CutWeight    = (sdr["cutweight"].ToString());
                    objtemp.HeatCode     = (sdr["HeatCode"].ToString());
                    objtemp.ColorCode    = (sdr["ColorCode"].ToString());
                    objtemp.RawMaterial  = (sdr["RawMaterial"].ToString());
                    objtemp.Section      = (sdr["Section"].ToString());
                    objtemp.PoRM         = (sdr["PORM"].ToString());
                    objtemp.PoSection    = (sdr["Section"].ToString());
                    objtemp.POSectionId  = Convert.ToInt32(sdr["SectionId"].ToString());
                    objtemp.PoNo         = (sdr["CustomerPONo"].ToString());
                    objtemp.CustomerName = (sdr["customerName"].ToString());
                    objtemp.CutWeight    = (sdr["cutweight"].ToString());
                    objtemp.grossWeight  = Convert.ToDecimal(sdr["grossweight"].ToString());
                    objtemp.DieNumber    = (sdr["DieNumber"].ToString());
                    objtemp.FeasibilityHammerRequired = Convert.ToInt32(sdr["FeasibilityHammerRequired"].ToString());
                    objtemp.CutLength         = Convert.ToDecimal(sdr["cutlength"].ToString());
                    objtemp.QtymentionedinPO  = Convert.ToDouble(sdr["QtymentionedinPO"].ToString());
                    objtemp.NatureOfWork      = Convert.ToInt32(sdr["FeasibilityNatureofWork"].ToString());
                    objtemp.ApprovalDate      = Convert.ToDateTime(sdr["ApprovalDate"].ToString());
                    objtemp.ApprovalDate      = Convert.ToDateTime(sdr["ApprovalDate"].ToString());
                    objtemp.PartName          = sdr["PartName"].ToString();
                    objtemp.ConditionOfSupply = sdr["FeasibilityConditionSupply1"].ToString();
                    objtemp.HeatTreatment     = (sdr["FeasibilityHeattreatment1"].ToString());
                    objtemp.HardnessMin       = sdr["hardnessmin"].ToString();
                    objtemp.HardnessMax       = sdr["hardnessmax"].ToString();
                    objtemp.HardnessUnit      = sdr["hardnessunits"].ToString();
                    objtemp.HeatCode          = sdr["HeatCode"].ToString();
                    objWoList.Add(objtemp);
                }

                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }
            return(objWoList);
        }
        public ActionResult NewWorkorder()
        {
            ssmtbl_WorkorderModel objWoMod = new ssmtbl_WorkorderModel();

            objWoMod.WorkorderNo = objWoData.GetMaxWorkorderNo();
            //ViewData["PoNo"] = objDrop.FrqRepOrder();
            objWoMod.DateOfIssue         = DateTime.Now;
            objWoMod.TargetDate          = DateTime.Now;
            objWoMod.ProductionStartDate = DateTime.Now;
            return(View(objWoMod));
        }
        public string InsertWorkorder(ssmtbl_WorkorderModel objWoMod)
        {
            string result = "Error Creating Workorder";

            try
            {
                var connection = gConnection.Connection();
                connection.Open();
                string     sqlstr = "ssmsp_Insert_Workorder";
                SqlCommand cmd    = new SqlCommand(sqlstr, GlobalVariables.gConn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                var wono = objWoMod.WorkorderNo;
                var pono = objWoMod.PoNo;
                wono = ("WO-" + pono + "-" + ((Convert.ToInt64(wono.Split('-')[1])).ToString("00000")));
                cmd.Parameters.AddWithValue("@WorkorderNo", wono);
                // cmd.Parameters.AddWithValue("@RawMaterial", objWoMod.RawMaterial);
                cmd.Parameters.AddWithValue("@HeatCode", objWoMod.HeatCode);
                //cmd.Parameters.AddWithValue("@Section", objWoMod.PoSection);
                //cmd.Parameters.AddWithValue("@DateOfIssue", objWoMod.DateOfIssue);
                cmd.Parameters.AddWithValue("@TargetDate", objWoMod.TargetDate);
                cmd.Parameters.AddWithValue("@CutWeight", objWoMod.CutWeight);
                cmd.Parameters.AddWithValue("@ColorCode", objWoMod.ColorCode);
                cmd.Parameters.AddWithValue("@PoNo", objWoMod.PoNo);
                cmd.Parameters.AddWithValue("@Status", "601");
                cmd.Parameters.AddWithValue("@CustomerName", objWoMod.CustomerName);
                cmd.Parameters.AddWithValue("@AllocatedRM", objWoMod.AllocatedRM);
                cmd.Parameters.AddWithValue("@AllocatedSection", objWoMod.AllocatedSection);
                cmd.Parameters.AddWithValue("@PoRM", objWoMod.PoRM);
                cmd.Parameters.AddWithValue("@PoSection", objWoMod.PoSection);
                cmd.ExecuteNonQuery();
                connection.Close();
                result = "Workorder Created Successfully!";
            }
            catch (Exception ex)
            {
                Global.ErrorHandlerClass.LogError(ex);
            }
            return(result);
        }