private void getBuilding(String lid, String trnDate, String amount, String description, String reference, String period, String code, bool alloc, DateTime dt, String oldReference)
    {
        String  sql = "SELECT Building, Code, AccNumber, Contra, DataPath FROM tblBuildings WHERE (Code = '" + code + "') ";
        DataSet ds  = utils.getData(sql, null);

        if (!alloc)
        {
            trnDate = dt.ToString("dd/MM/yyyy");
        }
        if ((ds != null) && (ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
        {
            DataRow dr   = ds.Tables[0].Rows[0];
            String  sql2 = "INSERT INTO tblExport (lid, trnDate, amount, building, code, description, reference, accnumber, contra, datapath, period, una)";
            sql2 += " VALUES('" + lid + "', '" + trnDate + "', '" + amount + "', '" + dr["Building"].ToString() + "', '" + code + "', '" + description + "', '" + reference;
            sql2 += "', '" + dr["AccNumber"].ToString() + "', '" + dr["Contra"].ToString() + "', '" + dr["DataPath"].ToString() + "', '" + period + "', '" + alloc.ToString() + "');";

            sql2 += "INSERT INTO tblMatch(statementRef, astroRef) VALUES('" + oldReference + "','" + reference + "')";
            //lblError.Text = sql2;
            String sqlReply = utils.executeQuery(sql2, null);
            if (sqlReply == "")
            {
                SqlDataSource5.Select(new DataSourceSelectArguments());
                SqlDataSource5.DataBind();
                GridView5.DataBind();
                SqlDataSource1.Select(new DataSourceSelectArguments());
                SqlDataSource1.DataBind();
                GridView6.DataBind();
            }
            else
            {
                lblError.Text = sqlReply;
            }
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int         rowIdx = int.Parse(e.CommandArgument.ToString());
        GridViewRow gvr    = GridView1.Rows[rowIdx];
        int         id     = 0;

        int.TryParse(gvr.Cells[1].Text, out id);
        String lid = gvr.Cells[2].Text;

        if (e.CommandName == "allocate")
        {
            try {
                String   building     = (gvr.FindControl("cmbBuilding") as DropDownList).SelectedValue;
                String   reference    = (gvr.FindControl("txtRef") as TextBox).Text;
                DateTime trnDate      = DateTime.Now;
                String   amt          = gvr.Cells[5].Text;
                String   description  = gvr.Cells[4].Text;
                int      period       = int.Parse((gvr.FindControl("cmbPeriod") as DropDownList).SelectedValue);
                bool     alloc        = false;
                DateTime dt           = DateTime.Parse(gvr.Cells[3].Text);
                String   build        = building;
                String   b2           = (building == "UNA" ? "" : building);
                String   oldReference = description;
                if (period != 0 && reference != "")
                {
                    String sql = "IF EXISTS (SELECT * FROM tblUnallocated WHERE lid = " + lid + ")";
                    sql += " UPDATE tblUnallocated SET amount = '" + amt + "', building = '" + building + "', allocatedDate = '" + trnDate.ToString("yyyy/MM/dd") + "', allocated = 'True', allocatedCode = '" + b2 + "', reference = '" + reference + "', period = " + period + " WHERE (lid = " + lid + ")";
                    sql += " ELSE ";
                    sql += " INSERT INTO tblUnallocated(lid, trnDate, building, amount, description, reference, period, allocatedDate, allocatedCode, trustpost)";
                    sql += " VALUES(" + lid + ", '" + gvr.Cells[3].Text + "', '" + building + "', " + amt.ToString() + ", '" + description + "', '" + reference + "', " + period.ToString();
                    sql += ", '" + trnDate + "', '" + b2 + "', 'False');";
                    sql += " UPDATE tblLedgerTransactions SET allocate = 'True' WHERE id = " + lid;
                    String sqlReply = utils.executeQuery(sql, null);
                    if (sqlReply == "")
                    {
                        getBuilding(lid, trnDate.ToString("dd/MM/yyyy"), amt, description, reference, period.ToString(), building, alloc, dt, oldReference);
                    }
                    else
                    {
                        lblError.Text = sqlReply;
                    }
                }
            } catch { }
        }
        else if (e.CommandName == "Remove")
        {
            String DeleteCommand = "DELETE FROM tblUnallocated WHERE id = " + id.ToString() + "; DELETE FROM tblLedgerTransactions WHERE id = " + lid;
            utils.executeQuery(DeleteCommand, null);
            SqlDataSource5.Select(new DataSourceSelectArguments());
            SqlDataSource5.DataBind();
            GridView1.DataBind();
        }
        SqlDataSource6.Select(new DataSourceSelectArguments());
        GridView1.DataBind();
    }
Beispiel #3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //SqlDataSource2.DataBind();
        //SqlDataSource4.DataBind();
        //SqlDataSource7.DataBind();
        SqlDataSource6.DataBind();
        SqlDataSource5.DataBind();

        //GridView1.DataBind();
        GridView2.DataBind();
        ////DetailsView1.DataBind();
        DetailsView2.DataBind();
        //System.Threading.Thread.Sleep(2000);
        //Response.Redirect("Admin.aspx?companyListBox.SelectedValue=" + companyListBox.SelectedValue);
    }
 protected void ASPxGridView4_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
 {
     SqlDataSource5.DataBind();
     ASPxGridView4.DataBind();
 }
 public void UpdateExam()
 {
     SqlDataSource5.DataBind();
     DropDownList4.DataBind();
 }
    protected void redirectToPendingPage()
    {
        string strSQL2 = "SELECT count(*) from dbo.projects where d_id = '" + lblDivisionCode.Text + "' and pj_code = '" + lblProjectCode.Text + "' and pj_status = '" + Request.QueryString["status"] + "'";

        SqlDataSource5.SelectCommand = strSQL2;
        SqlDataSource5.DataBind();

        DataView dv2 = (DataView)SqlDataSource5.Select(DataSourceSelectArguments.Empty);

        foreach (DataRow dRow in dv2.Table.Rows)
        {
            if (dRow["pj_name"] != null && dRow["pj_yut_id"] != null && dRow["pj_relateDept"] != null &&
                dRow["pj_year"] != null && dRow["pj_budget"] != null && dRow["pj_integrateProject"] != null)
            {
                if (dRow["pj_filter_q1"] == null || dRow["pj_filter_q2"] == null)
                {
                    Response.Redirect("project_filter.aspx");
                }
                else if (dRow["pj_background"] == null || dRow["pj_urgency"] == null ||
                         dRow["pj_risk_info"] == null || dRow["pj_risk_reduction1"] == null ||
                         dRow["pj_risk_reduction2"] == null || dRow["pj_risk_eval1"] == null ||
                         dRow["pj_risk_eval2"] == null || dRow["pj_risk_eval3"] == null)
                {
                    Response.Redirect("project_basicinfo.aspx");
                }
                else if (dRow["pj_category"] == null)
                {
                    Response.Redirect("project_category.aspx");
                }
                else if (dRow["pj_type"] == null)
                {
                    Response.Redirect("project_type.aspx");
                }
                else
                {
                    Response.Redirect("project_pickquestion.aspx");
                }
            }
            else
            {
                //populate data to each fields on this page
                if (dRow["pj_name"] != null)
                {
                    txtProjectName.Text = dRow["pj_name"].ToString();
                }
                if (dRow["pj_budget"] != null)
                {
                    txtBudget.Text = dRow["pj_budget"].ToString();
                }
                if (dRow["pj_integrateProject"] != null)
                {
                    txtIntegrate.Text = dRow["pj_integrateProject"].ToString();
                }
                if (dRow["pj_relateDept"] != null)
                {
                    txtRelate.Text = dRow["pj_relateDept"].ToString();
                }
                if (dRow["pj_year"] != null)
                {
                    ddlYear.SelectedValue = dRow["pj_year"].ToString();
                }
                if (dRow["pj_yut_id"] != null)
                {
                    ddlYudtasad.SelectedIndex = Convert.ToInt32(dRow["pj_yut_id"].ToString());
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["status"] != null && Session["status"].ToString().Equals("1"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorFunction", "errorMessages('Datele au fost actualizate cu succes!','success');", true);
                Session.Remove("status");
            }
        }
        catch (Exception err)
        {
        }
        if (!Page.IsPostBack)
        {
            try
            {
                MembershipUser userCheck = System.Web.Security.Membership.GetUser();
                if (userCheck != null)
                //   bool userCheck = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
                // if (userCheck)
                {
                    string username = System.Web.Security.Membership.GetUser().UserName.ToString();
                    string email    = System.Web.Security.Membership.GetUser().Email.ToString();
                    string user     = System.Web.Security.Membership.GetUser().ProviderUserKey.ToString();
                    Username.Text = username;
                    Email.Text    = email;

                    string        sqlVerif = "SELECT count(*) from PozeUseri where Id_User = @IdUser";
                    SqlConnection con      = ConnectionFactory.getNewSqlConnection();
                    con.Open();
                    SqlCommand com = new SqlCommand(sqlVerif, con);
                    com.Parameters.AddWithValue("IdUser", user);
                    int userCount = (int)com.ExecuteScalar();
                    con.Close();
                    if (userCount > 0)
                    {
                        string sql = "SELECT Poza_User FROM PozeUseri WHERE Id_User = @IdUser";
                        con = ConnectionFactory.getNewSqlConnection();
                        con.Open();
                        com = new SqlCommand(sql, con);
                        com.Parameters.AddWithValue("IdUser", user);
                        try
                        {
                            SqlDataReader r = com.ExecuteReader();
                            while (r.Read())
                            {
                                UserImage.ImageUrl = "~/pozeUseri/" + r["Poza_User"].ToString();
                            }
                        }
                        catch (Exception err)
                        {
                        }
                        con.Close();
                    }
                    else
                    {
                        UserImage.Attributes["src"] = "pozeUseri/DefaultUserIcon.png";
                    }

                    string userId = System.Web.Security.Membership.GetUser().ProviderUserKey.ToString();

                    SqlDataSource3.SelectCommand = "SELECT Carti.Id AS CartiId, Carti.Titlu AS CartiTitlu, Carti.Poza_Coperta, Autori.Prenume + ' ' + Autori.Nume AS NumeAutor, Genuri.Gen FROM Carti INNER JOIN Genuri ON Carti.Id_Gen = Genuri.Id INNER JOIN Autori ON Carti.Id_Autor = Autori.Id INNER JOIN CartiFavorite ON Carti.Id = CartiFavorite.Id_Carte WHERE CartiFavorite.Id_User = @user";
                    SqlDataSource3.SelectParameters.Clear();
                    SqlDataSource3.SelectParameters.Add("user", userId);
                    SqlDataSource3.DataBind();

                    SqlDataSource4.SelectCommand = "SELECT Carti.Id AS CartiId, Carti.Titlu AS CartiTitlu, Carti.Poza_Coperta, Autori.Prenume + ' ' + Autori.Nume AS NumeAutor, Genuri.Gen FROM Carti INNER JOIN Genuri ON Carti.Id_Gen = Genuri.Id INNER JOIN Autori ON Carti.Id_Autor = Autori.Id INNER JOIN CartiDeCitit ON Carti.Id = CartiDeCitit.Id_Carte WHERE CartiDeCitit.Id_User = @user";
                    SqlDataSource4.SelectParameters.Clear();
                    SqlDataSource4.SelectParameters.Add("user", userId);
                    SqlDataSource4.DataBind();

                    SqlDataSource5.SelectCommand = "SELECT Carti.Id AS CartiId, Carti.Titlu AS CartiTitlu, Carti.Poza_Coperta, Autori.Prenume + ' ' + Autori.Nume AS NumeAutor, Genuri.Gen FROM Carti INNER JOIN Genuri ON Carti.Id_Gen = Genuri.Id INNER JOIN Autori ON Carti.Id_Autor = Autori.Id INNER JOIN CartiCitite ON Carti.Id = CartiCitite.Id_Carte WHERE CartiCitite.Id_User = @user";
                    SqlDataSource5.SelectParameters.Clear();
                    SqlDataSource5.SelectParameters.Add("user", userId);
                    SqlDataSource5.DataBind();
                }
                else
                {
                    Response.Redirect("~/Home.aspx", false);
                }
            }
            catch (Exception err)
            {
            }
        }
        if (IsPostBack && UserProfilePicture.PostedFile != null)
        {
            try
            {
                if (UserProfilePicture.HasFile)
                {
                    String type = UserProfilePicture.PostedFile.ContentType.ToLower();
                    System.Drawing.Image img = System.Drawing.Image.FromStream(UserProfilePicture.PostedFile.InputStream);
                    int     height           = img.Height;
                    int     width            = img.Width;
                    decimal size             = Math.Round(((decimal)UserProfilePicture.PostedFile.ContentLength / (decimal)1024), 2);
                    if (size > 3500)
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorFunction", "errorMessages('Imagine prea mare! Dimensiunea maxima pentru imagine este 3,5MB.', 'danger');", true);
                    }
                    else
                    {
                        if (type.Contains("jpg") || type.Contains("jpeg"))
                        {
                            string user = System.Web.Security.Membership.GetUser().ProviderUserKey.ToString();
                            UserProfilePicture.SaveAs(Server.MapPath("~/pozeUseri/") + user + ".jpg");

                            string        sqlVerif = "SELECT count(*) from PozeUseri where Id_User = @IdUser";
                            SqlConnection con      = ConnectionFactory.getNewSqlConnection();
                            con.Open();
                            SqlCommand com = new SqlCommand(sqlVerif, con);
                            com.Parameters.AddWithValue("IdUser", user);
                            int userCount = (int)com.ExecuteScalar();
                            con.Close();
                            if (userCount > 0)
                            {
                                string sql = "UPDATE PozeUseri SET Poza_User = @Poza WHERE Id_User = @IdUser";
                                con = ConnectionFactory.getNewSqlConnection();
                                con.Open();
                                com = new SqlCommand(sql, con);
                                com.Parameters.AddWithValue("IdUser", user);
                                string urlPoza = user + ".jpg";
                                com.Parameters.AddWithValue("Poza", urlPoza);
                                com.ExecuteNonQuery();
                                con.Close();
                                UserImage.ImageUrl = "~/pozeUseri/" + urlPoza;
                            }
                            else
                            {
                                string sql = "INSERT INTO PozeUseri (Id_User, Poza_User) VALUES (@IdUser, @Poza)";
                                con = ConnectionFactory.getNewSqlConnection();
                                con.Open();
                                com = new SqlCommand(sql, con);
                                com.Parameters.AddWithValue("IdUser", user);
                                string urlPoza = user + ".jpg";
                                com.Parameters.AddWithValue("Poza", urlPoza);
                                com.ExecuteNonQuery();
                                con.Close();
                                UserImage.ImageUrl = "~/pozeUseri/" + urlPoza;
                            }
                            //Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorFunction", "errorMessages('Imaginea au fost actualizata cu succes!','success');", true);
                            //Session.Remove("status");

                            Session["status"] = "1";
                            Response.Redirect(Request.RawUrl, false);
                        }
                        //Response.Redirect(Request.RawUrl);
                        //Server.TransferRequest(Request.Url.AbsolutePath, false);
                    }
                }
            }
            catch (Exception err)
            {
            }
        }
    }
    protected void GridView5_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int         rowIdx = int.Parse(e.CommandArgument.ToString());
        GridViewRow gvr    = GridView5.Rows[rowIdx];
        int         id     = 0;

        int.TryParse(gvr.Cells[1].Text, out id);
        String lid = gvr.Cells[2].Text;

        if (e.CommandName == "allocate")
        {
            try {
                String   building    = (gvr.FindControl("cmbBuilding") as DropDownList).SelectedValue;
                String   reference   = (gvr.FindControl("txtRef") as TextBox).Text;
                DateTime trnDate     = DateTime.Now;
                String   amt         = (gvr.FindControl("txtAmount") as TextBox).Text;
                String   description = gvr.Cells[4].Text;
                int      period      = int.Parse((gvr.FindControl("cmbPeriod") as DropDownList).SelectedValue);
                DateTime dt          = DateTime.Parse(gvr.Cells[3].Text);
                String   b2          = (building == "UNA" ? "" : building);

                String oldReference = description;

                if (period != 0 && reference != "")
                {
                    String sql = "IF EXISTS (SELECT * FROM tblUnallocated WHERE lid = " + lid + ")";
                    sql += " UPDATE tblUnallocated SET amount = '" + amt + "', allocatedDate = '" + trnDate.ToString("yyyy/MM/dd") + "', allocated = 'True', allocatedCode = '" + b2 + "', ";
                    sql += " reference = '" + reference + "', period = " + period + " WHERE (lid = " + lid + ")";
                    sql += " ELSE ";
                    sql += " INSERT INTO tblUnallocated(lid, trnDate, amount, description, reference, period, allocatedDate, allocatedCode, trustpost)";
                    sql += " VALUES(" + lid + ", '" + gvr.Cells[3].Text + "', " + amt.ToString() + ", '" + description + "', '" + reference + "', " + period.ToString();
                    sql += ", '" + trnDate + "', '" + b2 + "', 'False');";
                    sql += " UPDATE tblLedgerTransactions SET allocate = 'True' WHERE id = " + lid;
                    //lblError.Text = sql;
                    String sqlReply = utils.executeQuery(sql, null);
                    if (sqlReply == "" && b2 != "")
                    {
                        getBuilding(lid, trnDate.ToString("dd/MM/yyyy"), amt, description, reference, period.ToString(), building, true, dt, oldReference);
                    }
                    else
                    {
                        lblError.Text = sqlReply;
                    }
                }
                else
                {
                    lblError.Text = "----";
                }
            } catch (Exception ex) {
                lblError.Text = ex.Message;
            }
        }
        else if (e.CommandName == "Remove")
        {
            int     counter = 0;
            DataSet ds      = utils.getData("SELECT count(*) as dupes FROM tblUnallocated WHERE lid = " + lid, null);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                counter = int.Parse(ds.Tables[0].Rows[0]["dupes"].ToString());
            }
            String DeleteCommand = "DELETE FROM tblUnallocated WHERE id = " + id.ToString() + ";";
            if (counter < 2)
            {
                DeleteCommand += " DELETE FROM tblLedgerTransactions WHERE id = " + lid;
            }
            utils.executeQuery(DeleteCommand, null);
            SqlDataSource5.Select(new DataSourceSelectArguments());
            SqlDataSource5.DataBind();
            GridView5.DataBind();
        }
    }