Ejemplo n.º 1
0
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        if (DListDownloadsTypes.SelectedValue == "-1")
        {
            Config.MsgBoxAjax("Sənədin növünü seçin!");
            return;
        }

        if (string.IsNullOrEmpty(TxtName.Text))
        {
            Config.MsgBoxAjax("Sənədin adını qeyd edin!");
            return;
        }

        string FileName = TxtName.Text.ClearTitle();

        if (DALC.CheckDownloadsByName(FileName, _DownloadsID))
        {
            Config.MsgBoxAjax("Bu sənəd adı, artıq istifadə edilib!");
            return;
        }

        if (_DownloadsID == 0)
        {
            if (!FileUp.HasFile)
            {
                Config.MsgBoxAjax("Fayl seçin!");
                return;
            }
        }

        if (DListStatus.SelectedValue == "-1")
        {
            Config.MsgBoxAjax("Sənədin statusunu qeyd edin!");
            return;
        }


        string  FileType          = "";
        decimal FileContentLength = 0;
        string  AllowType         = "-xls-xlsx-doc-docx-pdf-rar-zip-jpg-jpeg-png-txt-rtf-";

        if (FileUp.HasFile)
        {
            FileType = Path.GetExtension(FileUp.PostedFile.FileName);
            //FileName = string.Format("{0}{1}", FileName, FileType);
            FileContentLength = FileUp.PostedFile.ContentLength / 1024;

            if (AllowType.IndexOf(string.Format("-{0}-", FileType.Trim('.'))) < 0)
            {
                Config.MsgBoxAjax("Fayl formatı düzgün deyil!");
                return;
            }

            if (FileUp.PostedFile.CheckIfFileIsExecutable())
            {
                Config.MsgBoxAjax("Fayl formatı düzgün deyil!");
                return;
            }

            if (!FileUp.PostedFile.CheckFileContentLength(20))
            {
                Config.MsgBoxAjax("Faylın həcmi ən cox 20MB ola bilər!");
                return;
            }

            if (string.IsNullOrEmpty(FileName) || string.IsNullOrEmpty(FileName) || FileContentLength == 0)
            {
                Config.MsgBoxAjax("Xətalı fayl!");
                return;
            }

            try
            {
                FileUp.SaveAs(Server.MapPath(string.Format(_filePath, FileName + FileType)));
            }
            catch (Exception er)
            {
                DALC.ErrorLogs(string.Format("Sənədlər bölməsində fayl yüklənərkən xəta: {0}", er.Message));
                Config.MsgBoxAjax("Fayl yüklənərkən xəta baş verdi!");
                return;
            }
        }

        Dictionary <string, object> Dictionary = new Dictionary <string, object>();

        Dictionary.Add("DownloadsTypesID", int.Parse(DListDownloadsTypes.SelectedValue));
        Dictionary.Add("DataID", 0);
        Dictionary.Add("DisplayName", TxtName.Text);

        if (FileUp.HasFile)
        {
            Dictionary.Add("FileName", FileName);
            Dictionary.Add("FileType", FileType);
            Dictionary.Add("ContentLength", FileContentLength);
        }

        Dictionary.Add("Description", TxtDescription.Text);
        Dictionary.Add("IsActive", int.Parse(DListStatus.SelectedValue));


        int Result;

        if (_DownloadsID == 0)
        {
            Dictionary.Add("UsersID", DALC._GetUsersLogin.ID);
            Dictionary.Add("DownloadsQualityTypesID", (int)Tools.DownloadsQualityTypes.Qiymətləndirilməyib);
            Dictionary.Add("Data_Dt", DateTime.Now);
            Dictionary.Add("Add_Dt", DateTime.Now);
            Dictionary.Add("Add_Ip", Request.UserHostAddress.IPToInteger());

            Result = DALC.InsertDatabase(Tools.Table.Downloads, Dictionary);
            if (Result < 1)
            {
                Config.MsgBoxAjax(Config._DefaultErrorMessages);
                return;
            }
        }
        else
        {
            Dictionary.Add("WhereID", _DownloadsID);
            Result = DALC.UpdateDatabase(Tools.Table.Downloads, Dictionary);
            if (Result < 1)
            {
                Config.MsgBoxAjax(Config._DefaultErrorMessages);
                return;
            }
        }

        Config.MsgBoxAjax(Config._DefaultSuccessMessages, "/tools/downloads");
    }