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

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