Example #1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);

            if (filename == "")
            {
                return;
            }
            else
            {
                string UserID      = Session["UserID"].ToString();
                string strFileName = FileUpload1.PostedFile.FileName;
                int    lastIndex   = 0;

                if (strFileName.Contains('\\'))
                {
                    lastIndex = strFileName.LastIndexOf('\\');
                }
                strFileName = strFileName.Substring(lastIndex + 1);
                string txt = "";
                try
                {
                    txt = Session["AttactID"].ToString();
                }
                catch
                {
                    txt = "0";
                }
                string server     = "D:\\AttactFilePDN\\" + filename;
                string pathA      = ConfigurationManager.AppSettings["attactFile"].ToString();
                string pathServer = pathA + @"\XMLFileSystem.xml";
                int    IDA        = int.Parse(txt) + 1;
                FileUpload1.PostedFile.SaveAs(server);
                if (txtIDSystem.Text.Trim() == "")
                {
                    XmlDocument myXML = new XmlDocument();
                    if (IDA < 4)
                    {
                        myXML.Load(pathServer);
                        XmlElement parentElement = myXML.CreateElement("AttactID");
                        XmlElement ID            = myXML.CreateElement("ID");
                        ID.InnerText = IDA.ToString();
                        XmlElement eUserID = myXML.CreateElement("UserID");
                        eUserID.InnerText = UserID;
                        XmlElement FileName = myXML.CreateElement("FileName");
                        FileName.InnerText = server;
                        parentElement.AppendChild(ID);
                        parentElement.AppendChild(eUserID);
                        parentElement.AppendChild(FileName);
                        myXML.DocumentElement.AppendChild(parentElement);
                        myXML.Save(pathServer);
                        AttactID            = IDA;
                        Session["AttactID"] = IDA.ToString();
                    }
                    else
                    {
                        lblThongBao.Text = "Limited=3 file";
                    }
                    divAtt.Visible  = false;
                    divTemp.Visible = true;
                    HienThiFileDinhKem();
                }
                else
                {
                    DataTable dt = dal.LaySachProjectMTheoID(congty, txtIDSystem.Text.Trim());
                    if (dt.Rows.Count > 0)
                    {
                        string link1 = dt.Rows[0]["LinkFile"].ToString();
                        string link2 = dt.Rows[0]["LinkFile2"].ToString();
                        string link3 = dt.Rows[0]["LinkFile3"].ToString();
                        if (link1 == null || link1 == "")
                        {
                            dal.UpdateFileAttact1(congty, txtIDSystem.Text.Trim(), server);
                        }
                        else
                        {
                            if (link2 == null || link2 == "")
                            {
                                dal.UpdateFileAttact2(congty, txtIDSystem.Text.Trim(), server);
                            }
                            else
                            {
                                if (link3 == null || link3 == "")
                                {
                                    dal.UpdateFileAttact3(congty, txtIDSystem.Text.Trim(), server);
                                }
                                else
                                {
                                    lblThongBao.Text    = "Limited = 3 file";
                                    FileUpload1.Enabled = false;
                                    btnUpload.Enabled   = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        DateTime UserDate = DateTime.Today;

                        string jsysid = txtjsysid.Text.Trim();

                        string sysname = txtsysname.Text.Trim();
                        string sysmemo = txtsysmemo.Text.Trim();


                        string Yn = "";

                        string  sLeaderid = txtsLeaderid.Text.Trim();
                        string  edates    = txtedates.Text.Trim();
                        string  edatee    = txtedatee.Text.Trim();
                        decimal Spercent;
                        try
                        {
                            Spercent = decimal.Parse(txtPhanTram.Text.Trim());
                        }
                        catch
                        {
                            Spercent = 0;
                        }
                        if (Spercent == 100)
                        {
                            Yn = "1";
                        }
                        else
                        {
                            Yn = "0";
                        }
                        string sysnamevn = txtsysnamevn.Text.Trim();
                        string sysmemovn = txtsysmemovn.Text.Trim();

                        string them = (string)Session["themprojectm"];
                        if (them != null)
                        {
                            dal.ThemProjectm(congty, jsysid, sysname, sysmemo, UserID, UserDate, Yn, sLeaderid, DateTime.Parse(edates.ToString()), DateTime.Parse(edatee.ToString()), decimal.Parse(Spercent.ToString()), sysnamevn, sysmemovn);

                            DataTable dt1 = dal.LaySachProjectMTheoID(congty, txtIDSystem.Text.Trim());
                            if (dt1.Rows.Count > 0)
                            {
                                string link1 = dt1.Rows[0]["LinkFile"].ToString();
                                string link2 = dt1.Rows[0]["LinkFile2"].ToString();
                                string link3 = dt1.Rows[0]["LinkFile3"].ToString();
                                if (link1 == null || link1 == "")
                                {
                                    dal.UpdateFileAttact1(congty, txtIDSystem.Text.Trim(), server);
                                }
                                else
                                {
                                    if (link2 == null || link2 == "")
                                    {
                                        dal.UpdateFileAttact2(congty, txtIDSystem.Text.Trim(), server);
                                    }
                                    else
                                    {
                                        if (link3 == null || link3 == "")
                                        {
                                            dal.UpdateFileAttact3(congty, txtIDSystem.Text.Trim(), server);
                                        }
                                        else
                                        {
                                            lblThongBao.Text    = "Limited = 3 file";
                                            FileUpload1.Enabled = false;
                                            btnUpload.Enabled   = false;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    divAtt.Visible  = true;
                    divTemp.Visible = false;
                    HienThiFileDinhKemTHuc();
                }
            }
        }
Example #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DateTime UserDate = DateTime.Today;
            string   UserID   = (string)Session["UserID"];
            string   GSBH     = (string)Session["congty"];
            string   jsysid   = txtjsysid.Text.Trim();

            string sysname = txtsysname.Text.Trim();
            string sysmemo = txtsysmemo.Text.Trim();


            string Yn = "";

            string  sLeaderid = txtsLeaderid.Text.Trim();
            string  edates    = txtedates.Text.Trim();
            string  edatee    = txtedatee.Text.Trim();
            decimal Spercent;

            try
            {
                Spercent = decimal.Parse(txtPhanTram.Text.Trim());
            }
            catch
            {
                Spercent = 0;
            }
            if (Spercent == 100)
            {
                Yn = "1";
            }
            else
            {
                Yn = "0";
            }
            string sysnamevn = txtsysnamevn.Text.Trim();
            string sysmemovn = txtsysmemovn.Text.Trim();

            string them       = (string)Session["themprojectm"];
            string suaproject = (string)Session["suaprojectm"];

            if (UserID == null)
            {
            }
            else
            {
                if (them != null && suaproject == null)
                {
                    #region Set


                    #endregion
                    string pathA      = ConfigurationManager.AppSettings["attactFile"].ToString();
                    string pathServer = pathA + @"\XMLFileSystem.xml";
                    dal.ThemProjectm(GSBH, jsysid, sysname, sysmemo, UserID, UserDate, Yn, sLeaderid, DateTime.Parse(edates.ToString()), DateTime.Parse(edatee.ToString()), decimal.Parse(Spercent.ToString()), sysnamevn, sysmemovn);

                    XDocument doc = XDocument.Load(pathServer);

                    var list = doc.Root.Elements("AttactID").Where(p => p.Element("UserID").Value == UserID).ToList();
                    foreach (var item in list)
                    {
                        string Id       = (string)item.Element("ID");
                        string FileName = (string)item.Element("FileName");
                        if (Id == "1")
                        {
                            dal.UpdateFileAttact1(congty, jsysid, FileName);
                        }
                        else
                        {
                            if (Id == "2")
                            {
                                dal.UpdateFileAttact2(congty, jsysid, FileName);
                            }
                            else
                            {
                                dal.UpdateFileAttact3(congty, jsysid, FileName);
                            }
                        }

                        item.Remove();
                    }

                    // doc.Save(Server.MapPath("~/XML/XMLFileSystem.xml"));
                    doc.Save(pathServer);
                    txtjsysid.Text = "";

                    txtsysname.Text = "";
                    txtsysmemo.Text = "";

                    txtedates.Text    = DateTime.Today.ToString("yyyy/MM/dd");
                    txtedatee.Text    = DateTime.Today.ToString("yyyy/MM/dd");
                    txtPhanTram.Text  = "";
                    txtPDNO.Text      = "";
                    txtsysnamevn.Text = "";
                    txtsysmemovn.Text = "";

                    Session.Remove("suaprojectm");
                    Session.Remove("jsysid");


                    Session.Remove("lblsLeaderid");
                    HienThiFileDinhKemTHuc();
                    divTemp.Visible = false;
                    divAtt.Visible  = true;
                    Response.Redirect("WF_Projectm.aspx");
                }
                else
                {
                    if (checkEndMark.Checked == false)
                    {
                        dal.SuaProjectm(GSBH, jsysid, sysname, sysmemo, UserID, UserDate, Yn, sLeaderid, DateTime.Parse(edates.ToString()), DateTime.Parse(edatee.ToString()), decimal.Parse(Spercent.ToString()), sysnamevn, sysmemovn);
                    }
                    else
                    {
                        string ynAn = "8";
                        dal.XoaProjectm(congty, jsysid, ynAn);
                        dalProjectm.XoaProjectnTheoSYstem(congty, jsysid, ynAn);
                        dalProjects.XoaProjectsTheoSystem(congty, jsysid, ynAn);
                    }

                    Session.Remove("jsysid");


                    Session.Remove("lblsLeaderid");

                    Session.Remove("themprojectm");
                    Session.Remove("suaprojectm");
                    Response.Redirect("WF_Projectm.aspx");
                }
            }
            //
        }