protected void btnSave_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();

            dt = (DataTable)ViewState["Operator"];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DateTime       datetime      = DateTime.Parse(Convert.ToString(dt.Rows[i]["Date"]));
                string         formatteddate = datetime.ToString("yyyy-MM-dd");
                object         result;
                SqlParameter[] param = new SqlParameter[]
                {
                    new SqlParameter("@OPR", 1),
                    new SqlParameter("@PlantCode", Convert.ToString(dt.Rows[i]["PlantCode"])),
                    new SqlParameter("@Line", Convert.ToString(dt.Rows[i]["Line"])),
                    new SqlParameter("@Date", formatteddate),
                    new SqlParameter("@ShiftCode", Convert.ToString(dt.Rows[i]["ShiftCode"])),
                    new SqlParameter("@StationCode", Convert.ToString(dt.Rows[i]["StationCode"])),
                    new SqlParameter("@OperatorName", Convert.ToString(dt.Rows[i]["Name"])),
                    new SqlParameter("@Type", Convert.ToString(dt.Rows[i]["Type"])),
                    new SqlParameter("@EDP", Convert.ToString(dt.Rows[i]["EDP"])),
                    new SqlParameter("@CreatedBy", Convert.ToString(Session["username"]))
                };
                result = DBClass.ExecuteScalar_WithParam(param, "DM_SP_ADD_ASSIGNED_OPERATOR_DATA");
            }


            ScriptManager.RegisterStartupScript(this, this.GetType(),
                                                "alert3", "alert('Operator data submitted successfully');", true);
            GrdOperators.DataSource = null;
            GrdOperators.DataBind();
            btnSave.Visible = false;
            BindAssignedOperator();
        }
Пример #2
0
 public void BindOperatorsGrd()
 {
     try
     {
         SqlParameter[] param = new SqlParameter[]
         {
             new SqlParameter("@OPR", "8"),
             new SqlParameter("@PlantCode", lblplantcode.Text),
             new SqlParameter("@Line", lblline.Text),
             new SqlParameter("@ShiftCode", lblshift.Text),
             new SqlParameter("@Date", lbldate.Text),
         };
         DataTable Dt = new DataTable();
         Dt = DBClass.GetDatatable_WithParam(param, "DM_SP_GET_DATA");
         GrdOperators.DataSource = Dt;
         GrdOperators.DataBind();
     }
     catch (Exception ex)
     {
         _logger.Error(string.Concat("BindCompletedGrid::", ex.Message), ex);
     }
 }
Пример #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();

            dt = (DataTable)ViewState["Operator"];
            //object obj;
            //SqlParameter[] param = new SqlParameter[]
            //    {
            //    new SqlParameter("@OPR", 12),
            //    new SqlParameter("@plant", dt.Rows[0]["PlantCode"]),
            //    new SqlParameter("@user", Session["username"].ToString())
            //    };
            //obj = DBClass.ExecuteNonQuery_WithParam(param, "SP_OperatorMaster");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                object         result;
                SqlParameter[] param1 = new SqlParameter[]
                {
                    new SqlParameter("@OPR", 4),
                    new SqlParameter("@plant", Convert.ToString(dt.Rows[i]["PlantCode"])),
                    new SqlParameter("@query", Convert.ToString(dt.Rows[i]["OperatorName"])),
                    new SqlParameter("@edp", Convert.ToString(dt.Rows[i]["EDPNumber"])),
                    new SqlParameter("@user", Convert.ToString(Session["username"])),
                    new SqlParameter("@type", Convert.ToString(dt.Rows[i]["Type"]))
                };
                result = DBClass.ExecuteScalar_WithParam(param1, "SP_OperatorMaster");
            }


            ScriptManager.RegisterStartupScript(this, this.GetType(),
                                                "alert3", "alert('Operator data submitted successfully');", true);
            GrdOperators.DataSource = null;
            GrdOperators.DataBind();
            btnSave.Visible      = false;
            GrdOperators.Visible = false;
            bindgrid();
        }
        protected void BindExcel(string filepath, string Extension)
        {
            //DataTable dtExcel;
            //  DataTable dtFinal;
            string conStr = "";
            string isHDR  = "Yes";

            try
            {
                switch (Extension)
                {
                case ".xls":     //Excel 97-03
                    conStr = ConfigurationManager.ConnectionStrings["Excel03"].ConnectionString;
                    break;

                case ".xlsx":     //Excel 07
                    conStr = ConfigurationManager.ConnectionStrings["Excel07"].ConnectionString;
                    break;
                }
                conStr = String.Format(conStr, filepath, isHDR);
                OleDbConnection  connExcel = new OleDbConnection(conStr);
                OleDbCommand     cmdExcel  = new OleDbCommand();
                OleDbDataAdapter oda       = new OleDbDataAdapter();
                DataTable        dt        = new DataTable();
                cmdExcel.Connection = connExcel;
                connExcel.Open();
                DataTable dtExcelSchema;
                dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
                connExcel.Close();
                connExcel.Open();
                cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
                oda.SelectCommand    = cmdExcel;
                oda.Fill(dt);
                connExcel.Close();
                ////////////////
                bool      flag  = false;
                DataTable newdt = new DataTable();
                newdt.Columns.Add("PlantCode", typeof(string));
                newdt.Columns.Add("Line", typeof(string));
                newdt.Columns.Add("StationCode", typeof(string));
                newdt.Columns.Add("EDP", typeof(string));
                newdt.Columns.Add("Name", typeof(string));
                newdt.Columns.Add("Type", typeof(string));
                newdt.Columns.Add("ShiftCode", typeof(string));
                newdt.Columns.Add("Date", typeof(string));
                newdt.Columns.Add("Status", typeof(string));
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["PlantCode"].ToString() != null && dr["PlantCode"].ToString() != string.Empty)
                    {
                        if (dr["Line"].ToString() != null && dr["Line"].ToString() != "")
                        {
                            if (dr["StationCode"].ToString() != null && dr["StationCode"].ToString() != "")
                            {
                                if (dr["EDP"].ToString() != null && dr["EDP"].ToString() != "")
                                {
                                    if (dr["Name"].ToString() != null && dr["Name"].ToString() != "")
                                    {
                                        if (dr["Type"].ToString() != null && dr["Type"].ToString() != "")
                                        {
                                            if (dr["ShiftCode"].ToString() != null && dr["ShiftCode"].ToString() != "")
                                            {
                                                if (dr["Date"].ToString() != null && dr["Date"].ToString() != "")
                                                {
                                                    flag = true;
                                                }
                                                else
                                                {
                                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('Date is empty!')", true);
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('Shift code is empty!')", true);
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('Type is empty!')", true);
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('Name is empty!')", true);
                                        return;
                                    }
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('EDP is empty!')", true);
                                    return;
                                }
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('StationCode is empty!')", true);
                                return;
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('Line is empty!')", true);
                            return;
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('PlantCode is empty!')", true);
                        return;
                    }

                    if (flag == true)
                    {
                        DataRow        dr1 = newdt.NewRow();
                        string         result;
                        SqlParameter[] param = new SqlParameter[]
                        {
                            new SqlParameter("@PlantCode", Convert.ToString(dr["PlantCode"])),
                            new SqlParameter("@Line", Convert.ToString(dr["Line"])),
                            new SqlParameter("@StationCode", Convert.ToString(dr["StationCode"])),
                            new SqlParameter("@edp", Convert.ToString(dr["EDP"])),
                            new SqlParameter("@Date", Convert.ToDateTime(Convert.ToString(dr["Date"])).ToString("yyyy-MM-dd")),
                            new SqlParameter("@ShiftCode", Convert.ToString(dr["ShiftCode"])),
                            new SqlParameter("@OperatorName", Convert.ToString(dr["Name"])),
                        };
                        result             = DBClass.ExecuteScalar_WithParam(param, "SP_OperatorDetails").ToString();
                        dr1["PlantCode"]   = dr["PlantCode"];
                        dr1["Line"]        = dr["Line"];
                        dr1["StationCode"] = dr["StationCode"];
                        dr1["EDP"]         = dr["EDP"];
                        dr1["Name"]        = dr["Name"];
                        dr1["Type"]        = dr["Type"];
                        dr1["ShiftCode"]   = dr["ShiftCode"];
                        dr1["Date"]        = Convert.ToDateTime(dr["Date"]).ToString("yyyy-MM-dd");
                        dr1["Status"]      = result;

                        newdt.Rows.Add(dr1);

                        if (result != "OK")
                        {
                            count++;
                        }

                        if (count == 0)
                        {
                            btnSave.Visible       = true;
                            ViewState["Operator"] = dt;
                        }
                    }
                    //////////////////
                }
                GrdOperators.DataSource = newdt;
                //GrdOperators.DataSource = dt;
                GrdOperators.DataBind();
                //btnSave.Visible = true;
                //ViewState["Operator"] = dt;
                //    DataTable DTRequest = new DataTable();

                //    SqlParameter[] param = new SqlParameter[]
                //{
                //     new SqlParameter("@CreatedBy",Convert.ToString(Session["main_userCode"]) ),
                //    new SqlParameter("@t",dtExcel)
                //};

                //    DTRequest = DBclass.GetDatatable_WithParam(param, "SP_APP_Upload_Validation");

                //    GrdOperators.DataSource = DTRequest;
                //    GrdOperators.DataBind();
            }
            catch (Exception ex)
            {
                _logger.Error(string.Concat("uploadOperatorFile::", ex.Message), ex);
                if (ex.Message.Contains("Sheet1") == true)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('Sheet1 Not Found !')", true);
                }

                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "javascript:alert('" + ex.Message + "')", true);
                }

                btnSave.Visible = false;
                //  pnlMsgUploadIndex.Visible = true;
            }
            finally
            {
                // dtExcel.Dispose();
            }
        }