示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userName"] == null || !(Session["roleNumber"].ToString().Equals("2")))
            {
                Response.Redirect("NotAuthorizatedPage.aspx");
            }
            String myConnectionString;

            myConnectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(myConnectionString);

            conn.Open();
            string           querycity = "select * from city order by CityName";
            MySqlCommand     cmd       = new MySqlCommand(querycity, conn);
            MySqlDataAdapter da        = new MySqlDataAdapter {
                SelectCommand = cmd
            };
            DataSet ds = new DataSet();

            da.Fill(ds);
            if (!IsPostBack)
            {
                DropDownListCity.DataTextField = ds.Tables[0].Columns["CityName"].ToString();
                DropDownListCity.DataSource    = ds.Tables[0];
                DropDownListCity.DataBind();
                DropDownListCity.SelectedItem.Text = "";
            }
            string           querydistrict = "select * from district order by Name";
            MySqlCommand     cmddistrict   = new MySqlCommand(querydistrict, conn);
            MySqlDataAdapter dadistrict    = new MySqlDataAdapter {
                SelectCommand = cmddistrict
            };
            DataSet dsdistrict = new DataSet();

            dadistrict.Fill(dsdistrict);
            if (!IsPostBack)
            {
                DropDownListDistrict.DataTextField = dsdistrict.Tables[0].Columns["Name"].ToString();
                DropDownListDistrict.DataSource    = dsdistrict.Tables[0];
                DropDownListDistrict.DataBind();
                DropDownListDistrict.SelectedItem.Text = "";
            }
            string           queryneighborhood = "select * from neighborhood order by Name";
            MySqlCommand     cmdneighborhood   = new MySqlCommand(queryneighborhood, conn);
            MySqlDataAdapter daneighborhood    = new MySqlDataAdapter {
                SelectCommand = cmdneighborhood
            };
            DataSet dsneighborhood = new DataSet();

            daneighborhood.Fill(dsneighborhood);
            if (!IsPostBack)
            {
                DropDownListNeighborhood.DataTextField = dsneighborhood.Tables[0].Columns["Name"].ToString();
                DropDownListNeighborhood.DataSource    = dsneighborhood.Tables[0];
                DropDownListNeighborhood.DataBind();
                DropDownListNeighborhood.SelectedItem.Text = "";
            }

            conn.Close();
        }
示例#2
0
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            if (DropDownListDistrict.SelectedIndex <= 0)
            {
                LabelValidateDistrict.Text      = "Select District !!!";
                LabelValidateDistrict.ForeColor = System.Drawing.Color.Red;
                DropDownListDistrict.Focus();
            }

            else if (DropDownListTehsil.SelectedIndex <= 0)
            {
                LabelValidateTehsil.Text      = "Select Tehsil !!!";
                LabelValidateTehsil.ForeColor = System.Drawing.Color.Red;
                DropDownListTehsil.Focus();
            }
            else if (string.IsNullOrWhiteSpace(TextBoxName.Text))
            {
                RequiredFieldValidatorName.ErrorMessage = "Enter Name !!!";
                TextBoxName.Focus();
            }
            else if (string.IsNullOrWhiteSpace(TextBoxDesgination.Text))
            {
                RequiredFieldValidatorDesgination.ErrorMessage = "Enter Designation !!!";
                TextBoxDesgination.Focus();
            }
            else if (string.IsNullOrWhiteSpace(TextBoxContactNo.Text))
            {
                RequiredFieldValidatorContactNo.ErrorMessage = "Enter Contact No !!!";
                TextBoxDesgination.Focus();
            }
            else if (string.IsNullOrWhiteSpace(TextBoxApprentIssue.Text))
            {
                RequiredFieldValidatorApprentIssue.ErrorMessage = "Enter Apprent Issue!!!";
                TextBoxApprentIssue.Focus();
            }
            else if (string.IsNullOrWhiteSpace(TextBoxComments.Text))
            {
                RequiredFieldValidatorComments.ErrorMessage = "Enter Comment!!!";
                TextBoxComments.Focus();
            }
            else if (string.IsNullOrWhiteSpace(TextBoxSubheadnameLocation.Text))
            {
                RequiredFieldValidatorSubheadnameLocation.ErrorMessage = "Enter SubHead Name & Location!!!";
                TextBoxSubheadnameLocation.Focus();
            }
            else
            {
                var images     = new List <string>();
                int filelenght = Request.Files.Count;
                if (filelenght > 3)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        HttpPostedFile fu = Request.Files[i];

                        if (fu.ContentLength > 0)
                        {
                            try
                            {
                                string fileName = Path.GetFileName(fu.FileName);
                                fu.SaveAs(Server.MapPath("~/Upload/") + fileName);
                                string imagePath = fileName;
                                images.Add(imagePath);
                                lblmsg.Text      = "Files have been Uploaded";
                                lblmsg.ForeColor = System.Drawing.Color.Green;
                            }
                            catch (Exception ex)
                            {
                                lblmsg.Text      = "File Could not be uploaded" + ex.Message;
                                lblmsg.ForeColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < Request.Files.Count; i++)
                    {
                        HttpPostedFile fu = Request.Files[i];
                        if (fu.ContentLength > 0)
                        {
                            try
                            {
                                string fileName = Path.GetFileName(fu.FileName);
                                fu.SaveAs(Server.MapPath("~/Upload/") + fileName);
                                string imagePath = fileName;
                                images.Add(imagePath);
                                lblmsg.Text      = "Files have been Uploaded";
                                lblmsg.ForeColor = System.Drawing.Color.Green;
                            }
                            catch (Exception ex)
                            {
                                lblmsg.Text      = "File Could not be uploaded" + ex.Message;
                                lblmsg.ForeColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                }

                string[] authors = { "Agriculture", "AUQAF", "Board Revenue", "District ADP", "Drinking Water and Sanitation", "Elementary & Secondary Education", "Energy & Power", "Environment", "Establishment & Administration", "Excise & Taxation", "Finance", "Food", "Health", "Higher Education", "Home", "Housing", "Industries", "Information", "Labour", "Law & Justice", "Local Government", "Mines & Minerals", "MULTI SECTORAL DEVELOPMENT", "Population Welfare", "Relief & Rehabilitation", "Roads", "Social Welfare", "Special Initiatives", "Sports, Culture, Tourism, Archaeology & Youth Affairs", "ST&IT", "Transport", "Urban Development", "Water" };

                // Create a Random object
                Random rand = new Random();
                // Generate a random index less than the size of the array.
                int index = rand.Next(authors.Length);
                // Display the result.
                string dep = authors[index].ToString();
                string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
                conn = new SqlConnection(ConnectionString);
                conn.Open();
                using (var sqlCommand = new SqlCommand())
                {
                    sqlCommand.Connection  = conn;
                    sqlCommand.CommandText = "INSERT INTO [dbo].[tblReferral] ([UserID],[ProjectCode],[Division],[District],[Tehsil],[Department],[SubHeadNameLocation],[ReferralDate],[Apparent_Issue],[Name],[Desgination],[Contact],[Email],[Comments] ,[Attachment])VALUES(@userid,@ProjectCode,@Division,@Distric,@Tehsil,@Department,@SubHeadNameLocation,@SendingDate,@Apparent_Issue,@Name,@Desgination,@Contact,@Email,@Comment,@Attachment);" + "select scope_identity();";
                    sqlCommand.CommandType = System.Data.CommandType.Text;
                    sqlCommand.Parameters.AddWithValue("@ProjectCode", Convert.ToInt32(TextBoxProjCode.Text.Trim()));
                    sqlCommand.Parameters.AddWithValue("@Division", TextBoxDivision.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@Distric", DropDownListDistrict.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@Tehsil", DropDownListTehsil.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@userid", 1223);
                    sqlCommand.Parameters.AddWithValue("@Department", dep);
                    sqlCommand.Parameters.AddWithValue("@SubHeadNameLocation", TextBoxSubheadnameLocation.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@SendingDate", DateTime.Now.ToShortDateString());
                    sqlCommand.Parameters.AddWithValue("@Apparent_Issue", TextBoxApprentIssue.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@Name", TextBoxName.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@Desgination", TextBoxDesgination.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@Contact", Convert.ToInt32(TextBoxContactNo.Text.Trim()));
                    sqlCommand.Parameters.AddWithValue("@Email", TextBoxAssignTo.Text);
                    sqlCommand.Parameters.AddWithValue("@SubHead", TextBoxSubheadnameLocation.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@Comment", TextBoxComments.Text.Trim());
                    sqlCommand.Parameters.AddWithValue("@Attachment", string.Join("|", images.ToArray()));
                    var Referralid = sqlCommand.ExecuteScalar();
                    //sqlCommand.ExecuteNonQuery();
                    conn.Close();
                    ReferralID = Referralid.ToString();
                }
                conn = new SqlConnection(ConnectionString);
                conn.Open();
                using (var sqlCommand2 = new SqlCommand())
                {
                    sqlCommand2.Connection  = conn;
                    sqlCommand2.CommandText = "INSERT INTO [dbo].[tblReferralNotification] ([UserID],[ReferralID],[Msg])VALUES(110,@referralid,@msg)";
                    sqlCommand2.CommandType = System.Data.CommandType.Text;
                    sqlCommand2.Parameters.AddWithValue("@referralid", ReferralID.ToString());
                    sqlCommand2.Parameters.AddWithValue("@msg", "Project Referral ");
                    sqlCommand2.ExecuteNonQuery();
                }

                conn.Close();
                toEmail   = TextBoxAssignTo.Text;
                EmailSubj = "Project Referral Notification";
                EmailMsg  = "You have new Notication Check your Dashboard";
                //passing parameter to Email Method
                Email_Without_Attachment(toEmail, EmailSubj, EmailMsg);
                Labelnotif.Text = "<body onload=\"showContent()\"></body>";
                DropDownListDistrict.SelectedIndex = 0;
                TextBoxDivision.Text            = "Division";
                TextBoxName.Text                = "";
                TextBoxDesgination.Text         = "";
                TextBoxContactNo.Text           = "";
                TextBoxApprentIssue.Text        = "";
                TextBoxComments.Text            = "";
                TextBoxSubheadnameLocation.Text = "";
                TextBoxAssignTo.Text            = "";

                //Server.Transfer("ProjectReferralWizard.aspx", false);
            }
        }