예제 #1
0
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            List <ADuser> usr = new List <ADuser>();

            if (e.NewValues["manager"] != null)
            {
                usr = new ADconnector().GetUser(e.NewValues["manager"].ToString());
            }

            MSQLData.UpdateCommand = "UPDATE ue SET is_inv=@is_inv,manager=@manager,manager_uname=@muname,status_id=@sid,office=@office,comment=@comment,update_date=now(),uname=@uname,manager_placement=@mp WHERE id=@id";
            MSQLData.UpdateParameters.Add("@is_inv", e.NewValues["is_inv"].ToString().ToLower() == "false" ? "0" : "1");
            MSQLData.UpdateParameters.Add("@manager", e.NewValues["manager"]?.ToString());
            MSQLData.UpdateParameters.Add("@muname", usr.Count == 0 ? null : usr[0].samAccountName);
            MSQLData.UpdateParameters.Add("@mp", usr.Count == 0 ? null : usr[0].placement);
            MSQLData.UpdateParameters.Add("@sid", ((DropDownList)(GridView1.Rows[e.RowIndex].FindControl("statusDdl"))).SelectedValue);
            MSQLData.UpdateParameters.Add("@office", usr.Count == 0 ? null : usr[0].office);
            MSQLData.UpdateParameters.Add("@comment", e.NewValues["comment"]?.ToString());
            MSQLData.UpdateParameters.Add("@uname", user.uname);
            MSQLData.UpdateParameters.Add("@id", GridView1.DataKeys[e.RowIndex].Value.ToString());
            MSQLData.Update();

            // пишем изменение статуса
            Label l = GridView1.Rows[e.RowIndex].FindControl("statusL") as Label;

            if (l.Text != ((DropDownList)(GridView1.Rows[e.RowIndex].FindControl("statusDdl"))).SelectedItem.Text)
            {
                MSQLData.InsertCommand = "INSERT INTO status_history (date,old_status,new_status,uname) VALUES (now(),@os,@ns,@uname)";
                MSQLData.InsertParameters.Add("@os", l.Text);
                MSQLData.InsertParameters.Add("@ns", ((DropDownList)(GridView1.Rows[e.RowIndex].FindControl("statusDdl"))).SelectedItem.Text);
                MSQLData.InsertParameters.Add("@uname", user.uname);
                MSQLData.Insert();
            }
        }
예제 #2
0
        public void InsertUeData()
        {
            if (string.IsNullOrEmpty(invNumT.Text))
            {
                M1.SetMessage = "Не заполнен инвентаризационный номер!";
                MessageExtender.Show();
                return;
            }
            if (string.IsNullOrEmpty(supDocT.Text))
            {
                M1.SetMessage = "Не выбрана накладная!";
                MessageExtender.Show();
                return;
            }
            if (!supDocT.Text.Contains('-') && !supDocT.Text.Contains('('))
            {
                M1.SetMessage = "Неправильно выбрана накладная!";
                MessageExtender.Show();
                return;
            }
            List <ADuser> usr = new List <ADuser>();

            if (!string.IsNullOrEmpty(managerT.Text))
            {
                usr = new ADconnector().GetUser(managerT.Text);
            }
            comm = new MySqlCommand("INSERT IGNORE INTO ue (inv_number,serial_number,is_inv,type_id,model_id,manager,manager_uname,status_id,subdivision_id,office,ue_price,supdocs_id,comment,update_date,uname,manager_placement) VALUES (@inv_number,@sn,@is_inv,@type_id,@model_id,@manager,@manager_uname,@status_id,@subdivision_id,@office,@ue_price,@supdocs_id,@comment,now(),@uname,@mp)", conn);
            comm.Parameters.AddWithValue("@inv_number", invNumT.Text.Trim());
            comm.Parameters.AddWithValue("@sn", serNumT.Text.Trim());
            comm.Parameters.AddWithValue("@is_inv", isInvC.Checked ? 1 : 0);
            comm.Parameters.AddWithValue("@type_id", typeDdl.SelectedValue);
            comm.Parameters.AddWithValue("@model_id", modelsDdl.SelectedValue);
            comm.Parameters.AddWithValue("@manager", string.IsNullOrEmpty(managerT.Text) ? null : managerT.Text);
            comm.Parameters.AddWithValue("@manager_uname", usr.Count > 0 ? usr[0].samAccountName : null);
            comm.Parameters.AddWithValue("@status_id", statusDdl.SelectedValue);
            comm.Parameters.AddWithValue("@subdivision_id", subdivisionDdl.SelectedValue);
            comm.Parameters.AddWithValue("@office", string.IsNullOrEmpty(officeT.Text) ? null : officeT.Text);
            comm.Parameters.AddWithValue("@ue_price", priceT.Text.Replace(" ", ""));
            comm.Parameters.AddWithValue("@supdocs_id", supDocT.Text.Split('-')[0].Trim());
            comm.Parameters.AddWithValue("@comment", string.IsNullOrEmpty(commentT.Text) ? null : commentT.Text);
            comm.Parameters.AddWithValue("@mp", string.IsNullOrEmpty(subdivisionT.Text) ? null : subdivisionT.Text);
            comm.Parameters.AddWithValue("@uname", user.uname);
            conn.Open();
            comm.ExecuteNonQuery();
            if (usr.Count > 0) // если есть пользователь в AD, пишем его текущее положение в базу
            {
                comm = new MySqlCommand("INSERT IGNORE INTO manager_move (division,date,placement,uname,manager) VALUES (@division,now(),@placement,@uname,@manager)", conn);
                comm.Parameters.AddWithValue("@division", usr[0].office);
                comm.Parameters.AddWithValue("@placement", usr[0].placement);
                comm.Parameters.AddWithValue("@uname", usr[0].samAccountName);
                comm.Parameters.AddWithValue("@manager", usr[0].name);
                comm.ExecuteNonQuery();
            }
            conn.Close();
            GridView1.DataBind();
        }
예제 #3
0
        protected void searchManagerB_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(managerT.Text))
            {
                M1.SetMessage = "Поле не должно быть пустым!";
                MessageExtender.Show();
                return;
            }
            if (managerT.Text.Length < 2)
            {
                M1.SetMessage = "Минимальная длина фамилии 3 символа!";
                MessageExtender.Show();
                return;
            }

            List <ADuser> usr = new ADconnector().GetUser(managerT.Text);

            if (usr.Count > 0)
            {
                if (usr.Count == 1)
                {
                    managerT.Text     = usr[0].name;
                    subdivisionT.Text = usr[0].reply;
                    officeT.Text      = usr[0].office;
                }
                else
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add("ФИО");
                    dt.Columns.Add("Офис");
                    dt.Columns.Add("Подразделение");
                    foreach (ADuser one in usr)
                    {
                        dt.Rows.Add(one.name, one.office, one.reply);
                    }
                    dt.AcceptChanges();
                    UserGrid.DataSource = dt;
                    UserGrid.DataBind();
                    UserPanelExtender.Show();
                }
            }
            else
            {
                subdivisionT.Text = "<Не найдено!>";
                officeT.Text      = "<Не найдено!>";
            }
        }
예제 #4
0
 protected void findByUnameBtn_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(unameT.Text))
     {
         ADconnector ad  = new ADconnector();
         ADuser      usr = ad.GetByUname(unameT.Text);
         if (string.IsNullOrEmpty(usr.name))
         {
             fioT.Text          = "<Пользователь не найден!>";
             AddUserBtn.Enabled = false;
         }
         else
         {
             fioT.Text          = usr.name;
             AddUserBtn.Enabled = true;
             officeT.Text       = usr.office;
         }
     }
 }
예제 #5
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            CLogin login = new CLogin();

            if (login.Login(TextBox1.Text, TextBox2.Text))
            {
                // если прошли, читаем настройки, если пользователя нет, режем по максимуму права
                MySqlConnection conn       = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MySQLString"].ConnectionString);
                bool            user_found = false;
                MySqlCommand    comm       = new MySqlCommand("SELECT uname,fio,divisions_id,office,admin,super_admin FROM rights WHERE uname=@login", conn);
                comm.Parameters.AddWithValue("@login", TextBox1.Text);
                conn.Open();
                CUser           usr    = new CUser();
                MySqlDataReader reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    user_found = true;
                    usr        = new CUser
                    {
                        uname      = TextBox1.Text,
                        fio        = reader.IsDBNull(1) ? null : reader.GetString(1),
                        divisions  = reader.IsDBNull(2) ? null : reader.GetString(2),
                        office     = reader.IsDBNull(3) ? null : reader.GetString(3),
                        admin      = reader.GetBoolean(4),
                        superAdmin = reader.GetBoolean(5),
                        registered = true
                    };
                }
                reader.Close();
                conn.Close();
                // если пользователя не нашли, соберем по нему хоть что-нибудь.
                if (!user_found)
                {
                    ADconnector adc = new ADconnector();
                    ADuser      adu = adc.GetByUname(TextBox1.Text);
                    usr = new CUser
                    {
                        uname      = TextBox1.Text,
                        fio        = adu.name,
                        office     = adu.office,
                        admin      = false,
                        superAdmin = false,
                        registered = false
                    };
                }

                Session["_UEuser"] = usr;

                System.Web.Security.FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
                if (rememberCb.Checked)
                {
                    Response.Cookies["UEUname"].Expires = DateTime.Now.AddDays(30);
                    Response.Cookies["UEPwd"].Expires   = DateTime.Now.AddDays(30);
                }
                else
                {
                    Response.Cookies["UEUname"].Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies["UEPwd"].Expires   = DateTime.Now.AddDays(-1);
                }

                Response.Cookies["UEUname"].Value = TextBox1.Text;
                Response.Cookies["UEPwd"].Value   = TextBox2.Text;
            }
            else
            {
                Label1.Text = "Неправильный логин или пароль!";
            }
        }
예제 #6
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "FindAD")
            {
                int rowInd = Convert.ToInt32(e.CommandArgument);
                Session["_editRowIndex"] = rowInd;
                TextBox t  = GridView1.Rows[rowInd].FindControl("managerTb") as TextBox;
                Label   sd = GridView1.Rows[rowInd].FindControl("divisionFactL") as Label;
                if (string.IsNullOrEmpty(t.Text))
                {
                    M1.SetMessage = "Поле не должно быть пустым!";
                    MessageExtender.Show();
                    return;
                }
                if (t.Text.Length < 2)
                {
                    M1.SetMessage = "Минимальная длина фамилии 3 символа!";
                    MessageExtender.Show();
                    return;
                }

                List <ADuser> usr = new ADconnector().GetUser(t.Text);
                if (usr.Count > 0)
                {
                    if (usr.Count == 1)
                    {
                        t.Text  = usr[0].name;
                        sd.Text = usr[0].office + "<br/>" + usr[0].reply;
                    }
                    else
                    {
                        DataTable dt = new DataTable();
                        dt.Columns.Add("ФИО");
                        dt.Columns.Add("Офис");
                        dt.Columns.Add("Подразделение");
                        foreach (ADuser one in usr)
                        {
                            dt.Rows.Add(one.name, one.office, one.reply);
                        }
                        dt.AcceptChanges();
                        UserGrid.DataSource = dt;
                        UserGrid.DataBind();
                        UserPanelExtender.Show();
                    }
                }
                else
                {
                    sd.Text = "<Не найдено!>";
                }
            }
            else if (e.CommandName == "DuplicateUE")
            {
                int    rowInd  = Convert.ToInt32(e.CommandArgument);
                string mySQLid = GridView1.DataKeys[rowInd].Value.ToString();
                comm = new MySqlCommand("SELECT type_id,model_id,status_id,subdivision_id,ue_price FROM ue WHERE id=@id", conn);
                comm.Parameters.AddWithValue("@id", mySQLid);
                newUEDiv.Visible = true;
                conn.Open();
                reader = comm.ExecuteReader();
                string modelID = null;
                while (reader.Read())
                {
                    typeDdl.SelectedValue = reader.GetString(0);
                    modelID = reader.GetString(1);
                    statusDdl.SelectedValue      = reader.GetString(2);
                    subdivisionDdl.SelectedValue = reader.GetString(3);
                    priceT.Text = reader.GetString(4);
                }
                reader.Close();
                // тут изврат, строим таблицу моделей исходя из типа и выбираем его
                comm = new MySqlCommand("SELECT name,id FROM models WHERE type_id=@id", conn);
                comm.Parameters.AddWithValue("@id", typeDdl.SelectedValue);
                reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    modelsDdl.Items.Add(new ListItem(reader.GetString(0), reader.GetString(1)));
                }
                reader.Close();
                modelsDdl.SelectedValue = modelID;
                conn.Close();
            }
        }