/// <summary> /// 库存数量比对,重新设置库存数量 /// </summary> /// <param name="device_number">设备型号</param> /// <param name="device_count">下单数量</param> /// <returns></returns> public int GetIinventoryCount(string device_number, string device_count) { // 应该重新设置的库存数量 int count = -1; DataSet ds = OperaterBase.GetData("select * from Device_List where device_number = '" + device_number + "'"); // 说明查出来数据了 if (ds.Tables[0].Rows.Count > 0) { if (Convert.ToInt32(device_count) > Convert.ToInt32(ds.Tables[0].Rows[0]["device_count"])) { Label1.Text = "下单数量大于库存数量,库存数量为" + Convert.ToInt32(ds.Tables[0].Rows[0]["device_count"]); } else { // 数量正常,可以正常减去 count = Convert.ToInt32(ds.Tables[0].Rows[0]["device_count"]) - Convert.ToInt32(device_count); OperaterBase.CommandBySql("update Device_List set device_count=" + count + " where device_number='" + device_number + "'"); } } else { Label1.Text = "设备号有异常,请检查"; } return(count); }
/// <summary> /// 添加或更新用户 /// </summary> public void AddUser() { // 传参设备id int deviceId = Convert.ToInt32(Request["deviceId"]); string device_number = TextBox1.Text.Trim(); int device_count = Convert.ToInt32(TextBox2.Text.Trim()); // 判断是否是插入还是更新 if (Button1.CommandName == "Insert") { int num = OperaterBase.CommandBySql( "insert into Device_List ( device_number, device_count, is_delete) values ('" + device_number + "'," + device_count + ",0)"); if (num > 0) { Label1.Text = "插入成功"; // 跳转页面 Response.Redirect("device_list.aspx"); } } else if (Button1.CommandName == "Update") { int num = OperaterBase.CommandBySql("update Device_List set device_number='" + device_number + "',device_count=" + device_count + " where id=" + deviceId); if (num > 0) { Label1.Text = "更新成功"; // 跳转页面 Response.Redirect("device_list.aspx"); } } }
protected void Button1_Click(object sender, EventArgs e) { // 获取传递过来的员工id string staffId = Request["staffId"]; string order_number = TextBox1.Text; string device_number = DropDownList1.SelectedItem.Text; string device_count = TextBox3.Text; // 库存设置 int count = GetIinventoryCount(device_number, device_count); if (count == -1) { return; } string sql = "insert into Order_List ( order_number,order_date,order_staff, device_id, device_count,is_delete)values ('" + order_number + "','" + DateTime.Now.ToString() + "','" + staffId + "','" + device_number + "','" + device_count + "',0)"; int num = OperaterBase.CommandBySql(sql); if (num > 0) { Response.Redirect("order_list.aspx?staffId=" + staffId); } }
/// <summary> /// 图片上传 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { string filename = AvatarUpload(); int ID = Convert.ToInt32(Request["staffId"]); if (Button1.CommandName == "Update") { OperaterBase.CommandBySql("update Staff_Table set worker_avatar='" + filename + "' where Id=" + ID + ""); } }
/// <summary> /// 添加修改用户 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button2_Click(object sender, EventArgs e) { int ID = Convert.ToInt32(Request["staffId"]); string worker_num = TextBox1.Text.Trim(); string worker_name = TextBox2.Text.Trim(); string worker_avatar = Image1.ImageUrl; string worker_sex = Sex_Tb.SelectedValue.Trim(); string worker_age = TextBox4.Text.Trim(); string worker_mobile = TextBox5.Text.Trim(); string worker_password = TextBox6.Text.Trim(); string DropDownList1Text = DropDownList1.SelectedItem.Text; string DropDownList2Text = DropDownList2.SelectedItem.Text; string DropDownList3Text = DropDownList3.SelectedItem.Text; string sql = String.Empty; try { if (Button2.CommandName == "Insert") { sql = "insert into Staff_Table ( worker_num, worker_name, worker_avatar, worker_sex, worker_age, worker_mobile, worker_password, is_delete,s_province,s_city,s_district) values ('" + worker_num + "','" + worker_name + "','" + worker_avatar + "','" + worker_sex + "','" + worker_age + "','" + worker_mobile + "','" + worker_password + "',0,'" + DropDownList1Text + "','" + DropDownList2Text + "','" + DropDownList3Text + "')"; } else if (Button2.CommandName == "Update") { sql = "UPDATE Staff_Table SET worker_num = '" + worker_num + "', worker_name = '" + worker_name + "'," + " worker_sex = '" + worker_sex + "' , worker_age = '" + worker_age + "'," + "worker_mobile = '" + worker_mobile + "' , worker_password = '******' , s_province = '" + DropDownList1Text + "' , s_city = '" + DropDownList2Text + "' , s_district = '" + DropDownList3Text + "'where Id = " + ID; } int flag = OperaterBase.CommandBySql(sql); if (flag > 0) { // 跳转页面 Response.Redirect("manage_staff.aspx"); } } catch (Exception exception) { Console.WriteLine(exception); throw; } }
/// <summary> /// 表格更新或删除功能 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { int deviceId = Convert.ToInt32(((HiddenField)e.Item.FindControl("HiddenField1")).Value); if (e.CommandName == "Delete") { string sql = "update Device_List set is_delete=1 where id = " + deviceId; int flag = OperaterBase.CommandBySql(sql); if (flag > 0) { Response.Write("<script type='text/javascript'>alert(成功删除:'" + flag + "'条数据);</script>"); DropDownList1_SelectedIndexChanged(null, null); } } else if (e.CommandName == "Edit") { Response.Redirect("add_device.aspx?deviceId=" + deviceId); } }
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { int staffId = Convert.ToInt32(((HiddenField)e.Item.FindControl("staffId")).Value); // 删除员工 if (e.CommandName == "Delete") { string sql = "update Staff_Table set is_delete=1 where Id=" + staffId + ""; int flag = OperaterBase.CommandBySql(sql); if (flag > 0) { Response.Write("<script type='text/javascript'>alert(成功删除:'" + flag + "'条数据);</script>"); GetStaffData("select * from Staff_Table where is_delete=0"); } } else if (e.CommandName == "Edit") { Response.Redirect("add_staff.aspx?staffId=" + staffId); } }