mendian_banbie.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:10k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Text;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Data.SqlClient;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Drawing;
- using System.Net.Mail;
- using System.Net;
- using System.Net.Sockets;
- public partial class web_pos_c_mendian_banbie : System.Web.UI.Page
- {
- TableCell[] td=new TableCell[33];
- TableRow[] tr=new TableRow[11];
- int[] id = new int[33];
- TextBox[] tb = new TextBox[33];
- int m = 0;
- int n = 0;
- protected void Page_Load(object sender, EventArgs e)
- {
- int j = 0;
- for (int i = 0; i< 11; i++)
- {
- TableRow tr1 = new TableRow();
- TableCell td1 = new TableCell();
- td1.BorderWidth = Unit.Pixel(1);
- td1.BorderStyle = BorderStyle.Solid;
- TextBox textbox1 = new TextBox();
- textbox1.BorderStyle = BorderStyle.None;
- textbox1.ID = "txt" + j.ToString();
- tb[j] = textbox1;
- td1.Controls.Add(textbox1);
- td[j] = td1;
- tr1.Cells.Add(td1);
- TableCell td2 = new TableCell();
- td2.BorderWidth = Unit.Pixel(1);
- td2.BorderStyle = BorderStyle.Solid;
- TextBox textbox2 = new TextBox();
- textbox2.BorderStyle = BorderStyle.None;
- textbox2.ID = "txt" + (j+1).ToString();
- tb[j + 1] = textbox2;
- ;
- td2.Controls.Add(textbox2);
- td[j + 1] = td2;
- tr1.Cells.Add(td2);
- TableCell td3 = new TableCell();
- td3.BorderWidth = Unit.Pixel(1);
- td3.BorderStyle = BorderStyle.Solid;
- TextBox textbox3 = new TextBox();
- textbox3.BorderStyle = BorderStyle.None;
- textbox3.ID = "txt" + (j+2).ToString();
- tb[j + 2] = textbox3;
- td3.Controls.Add(textbox3);
- td[j+2]=td3;
- tr1.Cells.Add(td3);
- tr1.ID = "rows" + j.ToString();
- tr1.Visible = false;
- tr[i] = tr1;
- this.Table1.Rows.Add(tr1);
- j = j + 3;
- }
- show();
- }
- public void show()
- {
- int i = 0;
- int j = 0;
- this.Table1.Enabled = true;
- this.Table1.Visible = true;
- //string user_id = Session["user_id"].ToString();
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcomm4 = new SqlCommand("select f.name as name from OA_DEPARTMENT as f, OA_EMPLOYEE as g where f.id=g.department_id and g.id='"+Session["user_id"]+"'", conn1);
- string department = Convert.ToString(sqlcomm4.ExecuteScalar());
- conn1.Close();
- this.Label2.Text = department;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand sqlcomm3 = new SqlCommand("select * from oa_pos_type where department='" + department + "'", conn);
- SqlDataReader comm = sqlcomm3.ExecuteReader();
- while (comm.Read())
- {
- td[i].Visible = true;
- td[i].Enabled = false;
- tb[i].Text = comm["type"].ToString();
- td[i + 1].Visible = true;
- td[i + 1].Enabled = false;
- tb[i + 1].Text = comm["bengin_time"].ToString();
- td[i + 2].Visible = true;
- td[i + 2].Enabled = false;
- tb[i + 2].Text = comm["end_time"].ToString();
- tr[j].Visible = true;
- j = j + 1;
- i = i + 3;
- }
- m = i;
- n = j;
- comm.Close();
- conn.Close();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select count(*) from oa_pos_type where department='" + Label2.Text + "'", conn);
- int num= Convert.ToInt16(cmd.ExecuteScalar());
- if (num <= 9)
- {
- td[m].Visible = true;
- td[m].Enabled = true;
- td[m + 1].Visible = true;
- td[m + 1].Enabled = true;
- td[m + 2].Visible = true;
- td[m + 2].Enabled = true;
- tr[n].Visible = true;
- this.Button2.Visible = false;
- this.Button4.Visible = true;
- }
- else
- {
- this.Label3.Text = "班別數不能超過10";
- this.Label3.ForeColor = System.Drawing.Color.Red;
- }
- conn.Close();
- }
- protected void Button4_Click(object sender, EventArgs e)
- {
- int next_id = 1;
- TextBox tb1 = (TextBox)this.form1.FindControl("txt"+m.ToString());
- TextBox tb2 = (TextBox)this.form1.FindControl("txt" + (m+1).ToString());
- TextBox tb3 = (TextBox)this.form1.FindControl("txt" + (m+2).ToString());
- for (int k = 0; k < 33; k++)
- {
- id[k] = 0;
- }
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcomm5 = new SqlCommand("select count(id) as id from oa_pos_type", conn1);
- int num = Convert.ToInt16(sqlcomm5.ExecuteScalar());
- if (num != 0)
- {
- SqlCommand sqlcom = new SqlCommand("select max(id) from oa_pos_type", conn1);
- next_id = Convert.ToInt32(sqlcom.ExecuteScalar()) + 1;
- }
- conn1.Close();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- try
- {
- SqlCommand comm = new SqlCommand("insert into oa_pos_type(id,department,type,bengin_time,end_time)values('" + next_id + "','" + Label2.Text + "','" + Convert.ToString(tb1.Text) + "','" + Convert.ToString(tb2.Text) + "','" + Convert.ToString(tb3.Text) + "')", conn);
- comm.ExecuteNonQuery();
- this.Label3.Text = "班別設定成功";
- this.Label3.ForeColor = System.Drawing.Color.Red;
- }
- catch (Exception e1)
- {
- this.Label3.Text = "班別設定失敗,確定不存在相同的班別";
- this.Label3.ForeColor = System.Drawing.Color.Red;
- }
- conn.Close();
- Button2.Visible = true;
- Button4.Visible = false;
- show();
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- this.Button1.Visible = false;
- this.Button3.Visible = true;
- Table1.Enabled = true;
- for (int i = 0; i < 11; i++)
- {
- if (tr[i] != null)
- {
- tr[i].Enabled = true;
- }
- }
- for (int i = 0; i < 33; i++)
- {
- if (td[i] != null)
- {
- td[i].Enabled = true;
- }
- }
- }
- protected void Button3_Click(object senber, EventArgs e)
- {
- int j = 0;
- int p = 0;
- int max_id = 0;
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcom1 = new SqlCommand("select max(id) from oa_pos_type",conn1);
- max_id = Convert.ToInt32(sqlcom1.ExecuteScalar()) + 1;
- conn1.Close();
- TableRow[] trr = new TableRow[33];
- for(int i=0;i<m;i++)
- {
- trr[i]=(TableRow)this.form1.FindControl("rows"+i.ToString());
- }
- TextBox[] tbb = new TextBox[33];
- for (int i = 0; i < m; i++)
- {
- tbb[i] = (TextBox)this.form1.FindControl("txt" + i.ToString());
- }
- int k = 0;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand sqlcom = new SqlCommand("select id from oa_pos_type where department='"+Label2.Text+"' order by id",conn);
- SqlDataReader comm1 = sqlcom.ExecuteReader();
- while (comm1.Read())
- {
- id[k] = Convert.ToInt32(comm1["id"]);
- k=k+1;
- }
- comm1.Close();
- try
- {
- for (int q = 0; q < m; q = q + 3)
- {
- if (tbb[q]!=null)
- {
- if (id[j] != 0)
- {
- SqlCommand comm2 = new SqlCommand("update oa_pos_type set type='" + tbb[q].Text.ToString() + "',bengin_time='" + tbb[q + 1].Text.ToString() + "',end_time='" + tb[q + 2].Text.ToString() + "' where department='" + Label2.Text.ToString() + "' and id='" + id[j].ToString() + "'", conn);
- comm2.ExecuteNonQuery();
- j = j + 1;
- p = p + 1;
- }
- }
- }
- this.Label3.Text = "班别修改成功";
- this.Label3.ForeColor = System.Drawing.Color.Red;
- }
- catch(Exception ex)
- {
- Response.Write(ex.ToString());
- this.Label3.Text = "班別修改失敗";
- this.Label3.ForeColor = System.Drawing.Color.Red;
- }
- SqlCommand comm4 = new SqlCommand("delete from oa_pos_type where type=''", conn);
- comm4.ExecuteNonQuery();
- for(int i=0;i<m;i++)
- {
- if (trr[i] != null)
- {
- trr[i].Visible = false;
- }
- }
- conn.Close();
- Button1.Visible = true;
- Button3.Visible = false;
- show();
- }
- }