ChargeDetailEq.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:15k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.SessionState;
  10. using System.ComponentModel;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Web.UI.HtmlControls;
  13. using System.Data.SqlClient;
  14. using com.etong.BusinessRule.Zwf;
  15. using com.etong.DAL.FC;
  16. using com.etong.Inform;
  17. public partial class Workflow_ChargeDetailEq : System.Web.UI.Page
  18. {
  19.  
  20.     protected int projectid = -1;
  21.     protected void Page_Load(object sender, EventArgs e)
  22.     {
  23.         Response.Buffer = true;
  24.         Response.ExpiresAbsolute = System.DateTime.Now;
  25.         Response.Expires = 0;
  26.         Response.CacheControl = "no-cache";
  27.         string project = Request.QueryString["projectid"].ToString();
  28.         //string project = "22";
  29.         if (project != "")
  30.             projectid = Convert.ToInt32(project);
  31.         else
  32.         {
  33.             ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:您尚未登录或您登录已超时,请重新登录');location.href='../../login.aspx'</script>");
  34.             return;
  35.         }
  36.         if(!IsPostBack)
  37.         {
  38.             ((HtmlInputHidden)Page.FindControl("status")).Value = "0"; //不可见状态
  39.             ((HtmlInputHidden)Page.FindControl("TxtSeacher")).Value = "1";
  40.             PanelAdd.Visible = false;
  41.             EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
  42.             EFlyNM.Prj = projectid;
  43.             EFlyNM.sstatus = 1;
  44.             DataView dv = new DataView();
  45.             try
  46.             {
  47.                 dv = EFlyNM.ProEquGetData();
  48.             }
  49.             catch (Exception ex)
  50.             {
  51.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  52.                 return;
  53.             }
  54.             GridView1.DataSource = dv;
  55.             GridView1.DataBind();
  56.            BindParent();
  57.            dListChild.Attributes.Add("onchange","javascript:return DListChange()");
  58.            RBL_Type.Attributes.Add("onclick", "javascript:return DBLChange()");
  59.            TB_SearchContent.Attributes.Add("onkeypress", "EnterTextBox()");
  60.         }
  61.        
  62.     }
  63.     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  64.     {
  65.         PanelAdd.Visible = true;
  66.        
  67.         ((HtmlInputHidden)Page.FindControl("status")).Value="2"; //编辑状态
  68.         dListParent.SelectedItem.Text= GridView1.Rows[e.NewEditIndex].Cells[0].Text.Trim();
  69.         string dListParentid = dListParent.SelectedValue;
  70.         BindChild(dListParentid);
  71.         dListChild.SelectedItem.Text = GridView1.Rows[e.NewEditIndex].Cells[1].Text.Trim();
  72.         TB_wz.Text = GridView1.Rows[e.NewEditIndex].Cells[2].Text.ToString();
  73.         TB_UnitName.Text = GridView1.Rows[e.NewEditIndex].Cells[3].Text.Trim();
  74.         TB_Price.Text = GridView1.Rows[e.NewEditIndex].Cells[4].Text.Trim();
  75.         TB_Number.Text = GridView1.Rows[e.NewEditIndex].Cells[5].Text.Trim();
  76.         TB_Count.Text = GridView1.Rows[e.NewEditIndex].Cells[6].Text.Trim();
  77.        ((HtmlInputHidden)Page.FindControl("equipmentid")).Value = GridView1.DataKeys[e.NewEditIndex].Value.ToString().Trim();  // DataKeyNames;
  78.     }
  79.     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  80.     {
  81.         int equipmentid = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Value.ToString());
  82.         EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
  83.         EFlyNM.CommID = equipmentid;
  84.         EFlyNM.sstatus = 1;
  85.         CheckUserInfo UInfo = (CheckUserInfo)Session["checkuserinfo"];
  86.         EFlyNM.UserName = UInfo.EmpName;
  87.         try
  88.         {
  89.             EFlyNM.ProEquDelete();
  90.         }
  91.         catch (Exception ex)
  92.         {
  93.             this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  94.             return;
  95.         }
  96.         this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:删除成功!');", true);
  97.         ((HtmlInputHidden)Page.FindControl("txtcount")).Value = "0";
  98.         EFlyNM.Prj = projectid;
  99.         EFlyNM.sstatus = 1;
  100.         DataView dv = new DataView();
  101.         try
  102.         {
  103.             dv = EFlyNM.ProEquGetData();
  104.         }
  105.         catch (Exception ex)
  106.         {
  107.             this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  108.             return;
  109.         }
  110.         GridView1.DataSource = dv;
  111.         GridView1.DataBind();
  112.     }
  113.    
  114.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  115.     {
  116.         if (e.Row.RowIndex == 0)
  117.         {
  118.             ((HtmlInputHidden)Page.FindControl("txtcount")).Value = "0";
  119.         }
  120.         if (e.Row.RowType == DataControlRowType.DataRow)
  121.         {
  122.           decimal p=decimal.Parse(e.Row.Cells[4].Text.Trim());
  123.           int n=Convert.ToInt32(e.Row.Cells[5].Text.Trim());
  124.           e.Row.Cells[6].Text = Convert.ToString(p * n);
  125.           decimal count = decimal.Parse(((HtmlInputHidden)Page.FindControl("txtcount")).Value.Trim());
  126.           ((HtmlInputHidden)Page.FindControl("txtcount")).Value = Convert.ToString(count + decimal.Parse(e.Row.Cells[6].Text.Trim()));
  127.         }
  128.     }
  129.     protected void BT_Confirm_Click(object sender, ImageClickEventArgs e)
  130.     {
  131.     
  132.         PanelAdd.Visible = false;
  133.         string EquipmentName = dListParent.SelectedItem.Text.Trim();
  134.         string dListParentid = dListParent.SelectedValue.Trim();
  135.         string EquipmentSize = dListChild.SelectedItem.Text.Trim();         //--设备规格与型号
  136.         string UnitName = TB_UnitName.Text.Trim();
  137.         int wz_id = Convert.ToInt32(dListChild.SelectedValue.Trim());
  138.         int Number;
  139.        // if(TB_Number.Text.Trim()!="") Number = Convert.ToInt32(TB_Number.Text.Trim());
  140.       
  141.         try
  142.         {
  143.             Number = Convert.ToInt32(TB_Number.Text.Trim());
  144.         }
  145.         catch
  146.         {
  147.             Number = 0;
  148.             this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:数量必需大于零,提交失败!');", true);
  149.             return;
  150.         }
  151.         decimal Price;
  152.       //  if (TB_Price.Text.Trim()!="") Price= decimal.Parse(TB_Price.Text.Trim());
  153.         try
  154.         {
  155.             Price = decimal.Parse(TB_Price.Text.Trim());
  156.         }
  157.         catch
  158.         {
  159.             Price = 0;
  160.             this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:单价必需大于零,提交失败!');", true);
  161.             return;
  162.         }
  163.         EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
  164.         EFlyNM.Unit = UnitName;
  165.         EFlyNM.WZ = wz_id;
  166.         EFlyNM.CommName = EquipmentName;
  167.         EFlyNM.Num = Number;
  168.         EFlyNM.Prj = projectid;
  169.         EFlyNM.Mark = Price;
  170.         EFlyNM.CommSize = EquipmentSize;
  171.         CheckUserInfo UInfo = (CheckUserInfo)Session["checkuserinfo"];
  172.         EFlyNM.UserName = UInfo.EmpName;
  173.                
  174.         string status = ((HtmlInputHidden)Page.FindControl("status")).Value;
  175.         if (status == "1")  // 新增
  176.         {
  177.             int err = 1;
  178.             EFlyNM.status = 1;
  179.             try
  180.             {
  181.                 err=EFlyNM.ProEquInsert();
  182.             }
  183.             catch (Exception ex)
  184.             {
  185.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  186.                 return;
  187.             }
  188.             if (err == -1)
  189.             {
  190.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:不能新增相同物资代码!');", true);
  191.                 return;
  192.             }
  193.             else
  194.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:新增成功!');", true);
  195.          }
  196.          else if (status == "2")  //编辑
  197.          {
  198.              EFlyNM.status = 2;
  199.             HtmlInputHidden txt_equipmentid = ((HtmlInputHidden)Page.FindControl("equipmentid"));
  200.             EFlyNM.CommID = Convert.ToInt32(txt_equipmentid.Value.Trim());
  201.             EFlyNM.sstatus = 1;
  202.             int err = 0;
  203.             try
  204.             {
  205.                err= EFlyNM.ProEquUpdate();
  206.             }
  207.             catch (Exception ex)
  208.             {
  209.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  210.                 return;
  211.             }
  212.             if (err == -1)
  213.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:更新成功!');", true);
  214.             else if (err == 1) this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('未找到要更新的内容,请查证后再试!');", true);
  215.             else if (err == 2) this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('未发生变化无需更新,请查证后再试!');", true);
  216.         }
  217.         else
  218.         {
  219.             return;
  220.         }
  221.         EFlyNM.sstatus = 1;
  222.         DataView dv = new DataView();
  223.         try
  224.         {
  225.             dv = EFlyNM.ProEquGetData();
  226.         }
  227.         catch (Exception ex)
  228.         {
  229.             this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
  230.             return;
  231.         }
  232.         GridView1.DataSource = dv;
  233.         GridView1.DataBind();
  234.         TB_UnitName.Text = "";
  235.         TB_Price.Text = "0";
  236.         TB_Number.Text = "1";
  237.         TB_Count.Text = "0";
  238.         ((HtmlInputHidden)Page.FindControl("status")).Value = "0"; //不可见状态
  239.     }
  240.     protected void BT_Cancel_Click(object sender, ImageClickEventArgs e)
  241.     {
  242.         PanelAdd.Visible = false;
  243.         ((HtmlInputHidden)Page.FindControl("status")).Value = "0"; //不可见状态
  244.         TB_UnitName.Text = "";
  245.         TB_Price.Text = "";
  246.         TB_Number.Text = "";
  247.         TB_Count.Text = "";
  248.     }
  249.     protected void BindParent()
  250.     {
  251.         DataView dv = new DataView();
  252.         EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
  253.         dv = EFlyNM.GetBigWZList();
  254.         for (int i=0;i<dv.Table.Rows.Count;i++)
  255.         {
  256.             dListParent.Items.Add(new ListItem(dv.Table.Rows[i][2].ToString(),dv.Table.Rows[i][0].ToString()+dv.Table.Rows[i][1].ToString()));
  257.         }
  258.         dListParent.Items[0].Selected = true;
  259.         string str1 = dListParent.SelectedValue;
  260.         BindChild(str1);
  261.     }
  262.     protected void BindChild(string str)
  263.     {
  264.         str = "material_name where  wz_id like '" +str + "%'";
  265.         EtongFlyChouCode EFlyCode = new EtongFlyChouCode();
  266.         DataView dv = EFlyCode.BStringSelect("wz_id,wz_spec",str,2);
  267.         //string commStr = string.Format("select wz_id,wz_spec from material_name where  wz_id like  '{0}'", str);
  268.         dListChild.DataSource = dv;
  269.         dListChild.DataTextField = "wz_spec";
  270.         dListChild.DataValueField = "wz_id";
  271.         dListChild.DataBind();
  272.         TB_wz.Text = dListChild.SelectedValue.ToString();
  273.     }
  274.     protected void dListParent_SelectedIndexChanged(object sender, EventArgs e)
  275.     {
  276.         string dListParentid = dListParent.SelectedValue;
  277.         BindChild(dListParentid);
  278.     }
  279.     protected void IB_Search_Click(object sender, ImageClickEventArgs e)
  280.     {
  281.         int iSearch;
  282.         try 
  283.         {
  284.             iSearch= Convert.ToInt32(RBL_Type.SelectedValue.Trim());
  285.         }
  286.         catch 
  287.         {
  288.             iSearch =0;
  289.         }
  290.         string strContent=TB_SearchContent.Text.Trim();
  291.         string sFiled = "wz_id,wz_name,wz_spec";
  292.         string sTable = "material_name where ";
  293.         DataView dv = new DataView();
  294.         EtongFlyChouCode EFlyCode = new EtongFlyChouCode();
  295.         if (iSearch == 1)
  296.         {
  297.             Int64 iContent;
  298.             try
  299.             {
  300.                 iContent = Convert.ToInt64(strContent);
  301.             }
  302.             catch
  303.             {
  304.                 iContent = -1;
  305.             }
  306.             sTable = sTable + "wz_id=" + iContent.ToString();
  307.             dv = EFlyCode.BStringSelect(sFiled, sTable, 2);
  308.             if (dv.Table.Rows.Count > 0)
  309.             {
  310.                 if (iSearch == 1)
  311.                 {
  312.                     if (((HtmlInputHidden)Page.FindControl("status")).Value == "0") ((HtmlInputHidden)Page.FindControl("status")).Value = "1";
  313.                     PanelAdd.Visible = true;
  314.                     dListParent.Items.FindByValue(dListParent.SelectedValue).Selected = false;
  315.                     dListParent.Items.FindByValue(dv.Table.Rows[0][0].ToString().Substring(0, 4)).Selected = true;
  316.                     BindChild(dv.Table.Rows[0][0].ToString().Substring(0, 4));
  317.                     dListChild.Items.FindByValue(dListChild.SelectedValue).Selected = false;
  318.                     dListChild.Items.FindByValue(dv.Table.Rows[0][0].ToString()).Selected = true;
  319.                     TB_wz.Text = dv.Table.Rows[0][0].ToString();
  320.                 }
  321.             }
  322.             else
  323.             {
  324.                 this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:未找到对应的物资代码!');",true);
  325.             }
  326.         }//isercher 1
  327.         else if (iSearch == 2)
  328.         {
  329.             if (((HtmlInputHidden)Page.FindControl("status")).Value == "0") ((HtmlInputHidden)Page.FindControl("status")).Value = "1";
  330.             PanelAdd.Visible = true;
  331.             dListParent.Items.FindByValue(dListParent.SelectedValue).Selected = false;
  332.             dListParent.Items.FindByValue(TxtWZ.Value.ToString().Substring(0, 4)).Selected = true;
  333.             BindChild(TxtWZ.Value.ToString().Substring(0, 4));
  334.             dListChild.Items.FindByValue(dListChild.SelectedValue).Selected = false;
  335.             dListChild.Items.FindByValue(TxtWZ.Value.ToString()).Selected = true;
  336.             TB_wz.Text = TxtWZ.Value.ToString();
  337.         }
  338.     }
  339.     protected void IB_Add_Click(object sender, ImageClickEventArgs e)
  340.     {
  341.         PanelAdd.Visible = true;
  342.         ((HtmlInputHidden)Page.FindControl("status")).Value = "1"; //新增状态
  343.     }
  344.     //protected void dListChild_SelectedIndexChanged(object sender, EventArgs e)
  345.     //{
  346.     //    TB_wz.Text = dListChild.SelectedValue.ToString();
  347.     //}
  348. }