public string LoadStateFromStorage(string key)
    {
        StringBuilder sb    = new StringBuilder();
        string        query = "";
        string        sql   = "SELECT * FROM CUSTOM_REPORT_INDEX";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        if (dataReader["REPORT_QUERY"] != DBNull.Value)
                        {
                            byte[] byteArray = (Byte[])dataReader["REPORT_QUERY"];
                            query = Encoding.ASCII.GetString(byteArray);
                        }
                    }
                }
            }
        }
        return(query);
    }
    private void CollectPDFs(ZipFile zip_file, string dirObject)
    {
        //string path = WebTools.SessionDataPath();
        string sql        = "";
        string FileName   = "";
        string folderPath = WebTools.GetExpr("path", "dir_objects", " folder_name='" + dirObject + "'");
        string filePath   = string.Empty;

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            //Isometric
            sql = "SELECT * FROM VIEW_BULK_PDF_EXPORT WHERE USER_NAME='" + Session["USER_NAME"].ToString() + "' AND EXPORT_OPTION = '" + dirObject + "'";
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["PDF_FILE_NAME"];

                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }

                        string filee = folderPath + dataReader["PDF_FILE_NAME"];
                        if (File.Exists(folderPath + dataReader["PDF_FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["PDF_FILE_NAME"]);
                        }
                    }
                } //OracleDataReader1
            }     //OracleCommand1
        }         //OracleConnection
    }
Пример #3
0
    private void Update_List()
    {
        string user_name   = WebTools.GetExpr("USER_NAME", "USERS", " WHERE USER_ID = " + Request.QueryString["USER_ID"]);
        string queryString = "SELECT * FROM VIEW_USER_MODULE WHERE USER_ID=" + Request.QueryString["USER_ID"] + " AND MODULE_ID=" + ddlModule.SelectedValue + " ORDER BY SEQ";

        using (OracleConnection connection = WebTools.GetIpmsConnection())
        {
            OracleCommand command = new OracleCommand(queryString, connection);
            //connection.Open();
            using (OracleDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Role_ListBoxDestination.Items.Add(new Telerik.Web.UI.RadListBoxItem(
                                                          reader["HIDE_COL_NAME"].ToString(), reader["SEQ"].ToString()
                                                          ));


                    for (int i = 0; i < Role_ListBoxSource.Items.Count; i++)
                    {
                        if (Role_ListBoxSource.Items[i].Text.ToString() == reader["HIDE_COL_NAME"].ToString())
                        {
                            Role_ListBoxSource.Items.Remove(Role_ListBoxSource.Items[i]);
                        }
                    }
                }
            }
        }
    }
    private void Update_List()
    {
        string queryString = "SELECT * FROM VIEW_USERS_ROLE WHERE USER_ID=" + Session["popup_USER_ID"].ToString() + " ORDER BY ROLE_NAME";

        using (OracleConnection connection = WebTools.GetIpmsConnection())
        {
            OracleCommand command = new OracleCommand(queryString, connection);
            //connection.Open();
            using (OracleDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Role_ListBoxDestination.Items.Add(new Telerik.Web.UI.RadListBoxItem(
                                                          reader["ROLE_NAME"].ToString(), reader["ROLE_NAME"].ToString()
                                                          ));

                    for (int i = 0; i < Role_ListBoxSource.Items.Count; i++)
                    {
                        if (Role_ListBoxSource.Items[i].Value.ToString() == reader["ROLE_NAME"].ToString())
                        {
                            Role_ListBoxSource.Items.Remove(Role_ListBoxSource.Items[i]);
                        }
                    }
                }
            }
        }
    }
Пример #5
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string file_ext = Right(FileUpload1.FileName, 3);
            string FileName = WebTools.SessionDataPath() + "user_pic." + file_ext;

            if (File.Exists(FileName))
            {
                System.IO.File.Delete(FileName);
            }

            FileUpload1.SaveAs(FileName);

            FileInfo f = new FileInfo(FileName);
            if (f.Length > 200000)
            {
                Master.ShowWarn("File size can't be more than 200kb!");
                return;
            }

            byte[] byteArray = null;

            using (FileStream fs = new FileStream
                                       (FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                byteArray = new byte[fs.Length];

                int iBytesRead = fs.Read(byteArray, 0, (int)fs.Length);
            }

            string sql = "UPDATE USERS SET ACCOUNT_PIC=:ACCOUNT_PIC, ACCOUNT_PIC_EXT=:ACCOUNT_PIC_EXT WHERE PROJECT_ID=" + Session["PROJECT_ID"].ToString() +
                         " AND USER_NAME='" + Session["USER_NAME"].ToString() + "'";


            using (OracleConnection conn = WebTools.GetIpmsConnection())
            {
                using (OracleCommand cmd = new OracleCommand(sql, conn))
                {
                    cmd.Parameters.Add("ACCOUNT_PIC", OracleType.Blob);
                    cmd.Parameters[0].Value = byteArray;

                    cmd.Parameters.Add("ACCOUNT_PIC_EXT", OracleType.VarChar);
                    cmd.Parameters[1].Value = file_ext;

                    cmd.ExecuteNonQuery();
                }
            }

            Load_Profile_Picture();

            Master.ShowMessage("Picture Uploaded!");
        }
        catch (Exception ex)
        {
            Master.ShowError(ex.Message);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        con = WebTools.GetIpmsConnection();

        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
    }
Пример #7
0
    private void Load_Document()
    {
        if (string.IsNullOrEmpty(tc_id))
        {
            return;
        }

        string sql = "SELECT * FROM PIP_TEST_CARDS WHERE TC_ID=" + tc_id;

        string FilePath = "";
        string FileName = "";

        string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = dataReader["TC_ID"] + "_mtc.pdf";
                        FilePath = WebTools.SessionDataPath() + FileName;

                        if (File.Exists(FilePath))
                        {
                            File.Delete(FilePath);
                        }

                        if (dataReader["MTC_BLOB"] != DBNull.Value)
                        {
                            byte[] byteArray = (Byte[])dataReader["MTC_BLOB"];
                            using (FileStream fs = new FileStream(FilePath, FileMode.CreateNew, FileAccess.Write))
                            {
                                fs.Write(byteArray, 0, byteArray.Length);

                                if (PDF_URL_Label.Text.Length > 0)
                                {
                                    PDF_URL_Label.Text += "<br/>";
                                }

                                PDF_URL_Label.Text += string.Format("<a href='{0}' target='_blank'>{1}</a>",
                                                                    baseUrl + "SessionData/" + Session.SessionID.ToString() + @"\" + FileName,
                                                                    dataReader["TC_CODE"]);
                            }
                        }
                    }
                }
            }
        }

        if (PDF_URL_Label.Text == "")
        {
            PDF_URL_Label.Text = "No PDF";
        }
    }
    protected void btnDownloadIR_Click(object sender, EventArgs e)
    {
        if (itemsGrid.SelectedIndexes.Count == 0)
        {
            Master.ShowError("Select IRN to continue");
            return;
        }
        ZipFile zip_file      = new ZipFile();
        string  irn_id        = itemsGrid.SelectedValue.ToString();
        string  irn_no        = WebTools.GetExpr("IRN_NO", "PIP_PO_IRN", " WHERE IRN_ID='" + irn_id + "'");
        string  sql           = "";
        string  FileName      = "";
        string  folderPath    = WebTools.GetExpr("path", "dir_objects", " DIR_ID='" + 6 + "'");
        string  filePath      = string.Empty;
        string  path          = WebTools.SessionDataPath();
        string  zip_file_path = path + "IRN" + ".zip";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            //Isometric
            sql = "SELECT * FROM VIEW_PO_IRN_IR_FILES WHERE IRN_ID='" + irn_id + "'";
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["FILE_NAME"];

                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }

                        if (File.Exists(folderPath + dataReader["FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["FILE_NAME"], "files");
                        }
                    }
                } //OracleDataReader1
            }     //OracleCommand1
        }         //OracleConnection
        zip_file.Save(zip_file_path);
        var updateFile = new FileInfo(zip_file_path);

        Response.ContentType = "application/octet-stream";
        Response.AddHeader("content-disposition", "attachment;filename=\"" + Path.GetFileName(updateFile.FullName) + "\"");
        Response.AddHeader("content-length", updateFile.Length.ToString());
        Response.TransmitFile(updateFile.FullName);
        Response.Flush();
    }
    protected void btnUpdateWelders_Click(object sender, EventArgs e)
    {
        //New
        OracleConnection conn = WebTools.GetIpmsConnection();

        if (conn.State != ConnectionState.Open)
        {
            conn.Open();
        }
        OracleCommand cmd = new OracleCommand();

        cmd.CommandType = CommandType.Text;
        cmd.Connection  = conn;
        OracleCommand cmd2 = new OracleCommand();

        cmd2.CommandType = CommandType.Text;
        cmd2.Connection  = conn;

        //Root & Hot
        cmd.CommandText = "SELECT * FROM VIEW_JOINT_WELDERS_UPDATE WHERE ROOT_HOT_WELDER_UPDATE='Y'";
        OracleDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            cmd2.CommandText =
                "UPDATE PIP_SPOOL_JOINTS SET ROOT_HOT_WELDER='" + dr["ROOT_HOT_WELDER_NEW"] + "' WHERE JOINT_ID=" + dr["JOINT_ID"];
            cmd2.ExecuteNonQuery();
        }

        //Fill & Cap
        cmd.CommandText = "SELECT * FROM VIEW_JOINT_WELDERS_UPDATE WHERE FILL_CAP_WELDER_UPDATE='Y'";
        dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            cmd2.CommandText =
                "UPDATE PIP_SPOOL_JOINTS SET FILL_CAP_WELDER='" + dr["FILL_CAP_WELDER_NEW"] + "' WHERE JOINT_ID=" + dr["JOINT_ID"];
            cmd2.ExecuteNonQuery();
        }

        //Finally
        cmd.Dispose();
        cmd2.Dispose();
        conn.Close();
        conn.Dispose();

        NotificationBox.show_success("Joint Welders Updated!");
    }
    public void download_zip(int type_id, string ref_id, string downloadsuffix, string dir_obj, HttpResponse respone)
    {
        ZipFile zip_file = new ZipFile();

        // string irn_no = WebTools.GetExpr("MIR_NO", "PRC_MAT_INSP", " WHERE MIR_ID='" + mir_id+ "'");
        string sql           = "";
        string FileName      = "";
        string folderPath    = WebTools.GetExpr("path", "dir_objects", " DIR_OBJ='" + dir_obj + "'");
        string filePath      = string.Empty;
        string path          = WebTools.SessionDataPath();
        string zip_file_path = path + downloadsuffix + ".zip";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            //Isometric
            sql = "SELECT * FROM VIEW_UPLOAD_FILES WHERE TYPE_ID=" + type_id + " AND REF_ID='" + ref_id + "'";
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())

                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["FILE_NAME"];

                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }

                        if (File.Exists(folderPath + dataReader["FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["FILE_NAME"], "files");
                        }
                    }
                } //OracleDataReader1
            }     //OracleCommand1
        }         //OracleConnection
        zip_file.Save(zip_file_path);
        var updateFile = new FileInfo(zip_file_path);

        respone.ContentType = "application/octet-stream";
        respone.AddHeader("content-disposition", "attachment;filename=\"" + Path.GetFileName(updateFile.FullName) + "\"");
        respone.AddHeader("content-length", updateFile.Length.ToString());
        respone.TransmitFile(updateFile.FullName);
        respone.Flush();
    }
    private void Load_PDF()
    {
        string sql         = "SELECT * FROM VIEW_TEST_CARDS WHERE TC_ID=" + Session["popup_TC_ID"].ToString();
        string sg_FileName = WebTools.SessionDataPath();
        string baseUrl     = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
        string sg_pdf_html = "";
        string hc_pdf_html = "";
        string hc_url      = WebTools.GetExpr("PATH", "DIR_OBJECTS", " PROJECT_ID = '" + Session["PROJECT_ID"].ToString() + "' AND DIR_OBJ = 'MTC'");
        string hc_url1     = WebTools.GetExpr("PATH", "DIR_OBJECTS", " PROJECT_ID = '" + Session["PROJECT_ID"].ToString() + "' AND DIR_OBJ = 'MTC'");


        string hc_asp_url  = WebTools.GetExpr("ASP_PATH", "DIR_OBJECTS", " PROJECT_ID = '" + Session["PROJECT_ID"].ToString() + "' AND DIR_OBJ = 'MTC'");
        string hc_asp_url1 = WebTools.GetExpr("ASP_PATH", "DIR_OBJECTS", " PROJECT_ID = '" + Session["PROJECT_ID"].ToString() + "' AND DIR_OBJ = 'MTC'");


        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        // HC_PDF_BLOB
                        {
                            string hc_FileName = dataReader["PDF_FILE_NAME"].ToString();
                            hc_url = hc_url1 + hc_FileName;
                            if (File.Exists(hc_url))
                            {
                                hc_asp_url   = hc_asp_url1 + hc_FileName;
                                hc_pdf_html += "<br/>";

                                hc_pdf_html += string.Format("<a href='{0}' target='_blank'>{1}</a>",
                                                             hc_asp_url,
                                                             dataReader["PDF_TITLE"]);
                            }
                        }
                    } // dataReader.Read()

                    if (hc_pdf_html.Length > 0)
                    {
                        PDF_URL_Label.Text += "<b>MTC PDF</b><br/>" + hc_pdf_html + "<br/>";
                    }
                }
            }
        }
    }
    protected void cboJoints_SelectedIndexChanged(object sender, EventArgs e)
    {
        WPS_NO_RadAutoCompleteBox.Enabled = true;
        WPS_NO_RadAutoCompleteBox.Entries.Clear();

        if (IsPostBack)
        {
            OracleConnection conn = WebTools.GetIpmsConnection();
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }

            OracleCommand cmd = new OracleCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conn;


            cmd.CommandText = "SELECT * FROM PIP_SPOOL_JOINTS WHERE JOINT_ID=" + cboJoints.SelectedValue.ToString();
            using (OracleDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    txtReportNo.Text = dr["WELD_REP_NO"].ToString();
                    txtInsp.Text     = dr["WELD_INSP"].ToString();

                    if (!string.IsNullOrEmpty(dr["WPS_NO"].ToString()))
                    {
                        string wps_no = dr["WPS_NO"].ToString();
                        WPS_NO_RadAutoCompleteBox.Entries.Add(new Telerik.Web.UI.AutoCompleteBoxEntry(wps_no, wps_no));
                    }

                    if (!string.IsNullOrEmpty(dr["WELD_DATE"].ToString()))
                    {
                        txtWeldDate.SelectedDate = DateTime.Parse(dr["WELD_DATE"].ToString());
                    }
                }
            }

            //Finally
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
        }
    }
    public void SaveStateToStorage(string key, string serializedState)
    {
        OracleConnection connection = WebTools.GetIpmsConnection();

        byte[] byteArray = null;
        byteArray = Encoding.ASCII.GetBytes(serializedState);
        string query = "UPDATE CUSTOM_REPORT_INDEX SET REPORT_QUERY=:REPORT_QUERY";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            using (OracleCommand cmd = new OracleCommand(query, connection))
            {
                cmd.Parameters.Add("REPORT_QUERY", OracleType.Blob);
                cmd.Parameters[0].Value = byteArray;
                cmd.ExecuteNonQuery();
            }
        }
    }
Пример #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        con = WebTools.GetIpmsConnection();

        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }

        try
        {
            adp = new OracleDataAdapter("SELECT USER_NAME,EMAIL,CODE FROM USERS WHERE CODE='" + Request.QueryString["CODE"].ToString()
                                        + "' AND(EMAIL='" + Request.QueryString["EMAIL"].ToString() + "' OR USER_NAME='" + Request.QueryString["USER_NAME"].ToString()
                                        + "')", con);


            dt = new DataTable();
            adp.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                divExpire.Visible      = true;
                divpwd1.Visible        = false;
                divpwd2.Visible        = false;
                btn_change_pwd.Visible = false;

                return;
            }
            else
            {
                divExpire.Visible      = false;
                divpwd1.Visible        = true;
                divpwd2.Visible        = true;
                btn_change_pwd.Visible = true;
            }
        }
        catch (Exception ex)
        {
            lbl_msg.Text      = ex.Message;
            lbl_msg.ForeColor = System.Drawing.Color.Red;
        }
        finally
        {
        }
    }
Пример #15
0
    private void Load_Profile_Picture()
    {
        string sql = "SELECT * FROM USERS WHERE PROJECT_ID=" + Session["PROJECT_ID"].ToString() + " AND USER_NAME='" + Session["USER_NAME"].ToString() + "'";

        string FilePath = "";

        string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        if (dataReader["ACCOUNT_PIC"] != DBNull.Value)
                        {
                            Random rnd = new Random();

                            string file_name = rnd.Next(1000, 9999).ToString() + "." + dataReader["ACCOUNT_PIC_EXT"];

                            FilePath = WebTools.SessionDataPath() + file_name;

                            if (File.Exists(FilePath))
                            {
                                File.Delete(FilePath);
                            }

                            byte[] byteArray = (Byte[])dataReader["ACCOUNT_PIC"];
                            using (FileStream fs = new FileStream(FilePath, FileMode.CreateNew, FileAccess.Write))
                            {
                                fs.Write(byteArray, 0, byteArray.Length);

                                AccountImage.ImageUrl = baseUrl + "SessionData/" + Session.SessionID.ToString() + @"/" + file_name;
                                AccountImage.DataBind();
                            }
                        }
                    }
                }
            }
        }
    }
    private void CreateTextFile(string file_name, string sql)
    {
        StreamWriter sr = new StreamWriter(file_name);

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        sr.WriteLine(dr["TEXT_DATA"].ToString());
                    }
                } // dr
            }     // cmd
        }         // conn

        sr.Close();
        sr.Dispose();
    }
Пример #17
0
    protected void btnSubmit_Click1(object sender, EventArgs e)
    {
        string USER_ID = Request.QueryString["USER_ID"];

        OracleConnection connection = WebTools.GetIpmsConnection();
        OracleCommand    command    = new OracleCommand();

        command.Connection  = connection;
        command.CommandType = CommandType.Text;

        try
        {
            //Save Roles
            //============================================================
            WebTools.ExeSql("DELETE USER_MODULE_ROLES WHERE USER_ID=" + USER_ID + " AND MODULE_ID=" + ddlModule.SelectedValue);

            foreach (Telerik.Web.UI.RadListBoxItem role in Role_ListBoxDestination.Items)
            {
                command.CommandText = "INSERT INTO USER_MODULE_ROLES (USER_ID, SEQ,MODULE_ID) VALUES(" + USER_ID + ",'" + role.Value.ToString() + "'," + ddlModule.SelectedValue + " )";

                command.ExecuteNonQuery();
            }
            //============================================================


            Master.show_success(" Saved!");
        }
        catch (Exception ex)
        {
            Master.show_error(ex.Message);
        }
        finally
        {
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }
    }
    protected void btnSubmit_Click1(object sender, EventArgs e)
    {
        string USER_ID = Session["popup_USER_ID"].ToString();

        OracleConnection connection = WebTools.GetIpmsConnection();
        OracleCommand    command    = new OracleCommand();

        command.Connection  = connection;
        command.CommandType = CommandType.Text;

        try
        {
            if (txtPassword.Enabled == true)
            {
                if (txtPassword.Text.Length == 0)
                {
                    Master.show_error("No Password provided!");
                    return;
                }
                else if (txtPassword.Text.Length < 5)
                {
                    Master.show_error("Minimum Password Length is 5!");
                    return;
                }
                else if (txtPassword.Text != txtPassword2.Text)
                {
                    Master.show_error("Password does not match!");
                    return;
                }

                WebTools.ExeSql("UPDATE USERS SET PASSKEY='" + WebTools.MD5Str(txtPassword.Text.ToLower()) + "' WHERE USER_ID=" + USER_ID);
            }

            //Save Roles
            //============================================================
            WebTools.ExeSql("DELETE USERS_ROLE WHERE USER_ID=" + USER_ID);

            foreach (Telerik.Web.UI.RadListBoxItem role in Role_ListBoxDestination.Items)
            {
                command.CommandText = "INSERT INTO USERS_ROLE(USER_ID, ROLE_NAME) VALUES(" + USER_ID + ",'" + role.Value.ToString() + "')";

                command.ExecuteNonQuery();
            }
            //============================================================

            if (txtPassword.Enabled == true)
            {
                Master.show_success("User Info Saved and Password Changed!");
            }
            else
            {
                Master.show_success(txtUserName.Text + " Saved!");
            }
        }
        catch (Exception ex)
        {
            Master.show_error(ex.Message);
        }
        finally
        {
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }
    }
Пример #19
0
    private void Save_Welding()
    {
        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            // update weld_date, wps_no
            using (OracleCommand cmd =
                       new OracleCommand("SELECT DISTINCT JOINT_ID, WELDED_DATE, WPS_NO, WELD_DATE_UPD, WPS_NO_UPD FROM VIEW_FIELD_WELDING_IMP_A " +
                                         "WHERE JOINT_ID IS NOT NULL AND CAT_ID IN (2, 4) AND (WELD_DATE_UPD='Y' OR WPS_NO_UPD='Y')", conn))
            {
                using (OracleDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        OracleCommand cmd2 = new OracleCommand();
                        cmd2.Connection  = conn;
                        cmd2.CommandText = "UPDATE PIP_SPOOL_JOINTS SET ";

                        bool have_col = false;
                        if (dr["WELD_DATE_UPD"].ToString() == "Y")
                        {
                            have_col          = true;
                            cmd2.CommandText += "WELD_DATE='" + DateTime.Parse(dr["WELDED_DATE"].ToString()).ToString("dd-MMM-yyyy") + "'";
                        }

                        if (dr["WPS_NO_UPD"].ToString() == "Y")
                        {
                            if (have_col)
                            {
                                cmd2.CommandText += ",";
                            }

                            have_col          = true;
                            cmd2.CommandText += "WPS_NO='" + dr["WPS_NO"].ToString() + "'";
                        }

                        if (have_col)
                        {
                            cmd2.CommandText += " WHERE JOINT_ID=" + dr["JOINT_ID"].ToString();
                            cmd2.ExecuteNonQuery();
                        }

                        cmd2.Dispose();
                    } // while
                }     // dr
            }         // cmd

            // add new welders
            using (OracleCommand cmd = new OracleCommand("SELECT * FROM VIEW_FIELD_WLD_WELDERS WHERE WELDER_ID IS NULL", conn))
            {
                using (OracleDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        OracleCommand cmd2 = new OracleCommand();
                        cmd2.Connection  = conn;
                        cmd2.CommandText = "INSERT INTO PIP_WELDERS(WELDER_NO, W_NAME, SC_ID, EMP_DATE, PROJECT_ID) " +
                                           "VALUES (:WELDER_NO, :W_NAME, :SC_ID, :EMP_DATE, :PROJECT_ID)";

                        cmd2.Parameters.Add("WELDER_NO", OracleType.VarChar);
                        cmd2.Parameters["WELDER_NO"].Value = dr["WELDER_NO"].ToString();

                        cmd2.Parameters.Add("W_NAME", OracleType.VarChar);
                        cmd2.Parameters["W_NAME"].Value = dr["WELDER_NO"].ToString();

                        cmd2.Parameters.Add("SC_ID", OracleType.Number);
                        cmd2.Parameters["SC_ID"].Value = dr["SUB_CON_ID"].ToString();

                        cmd2.Parameters.Add("EMP_DATE", OracleType.DateTime);
                        cmd2.Parameters["EMP_DATE"].Value = DateTime.Now.ToString("dd-MMM-yyyy");

                        cmd2.Parameters.Add("PROJECT_ID", OracleType.Number);
                        cmd2.Parameters["PROJECT_ID"].Value = Session["PROJECT_ID"].ToString();

                        cmd2.ExecuteNonQuery();
                    } // while
                }     // dr
            }         // new welders added

            // add weling details
            using (OracleCommand cmd = new OracleCommand("SELECT * FROM VIEW_FIELD_WLD_DETAIL", conn))
            {
                using (OracleDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        OracleCommand cmd2 = new OracleCommand();
                        cmd2.Connection  = conn;
                        cmd2.CommandText = "INSERT INTO PIP_SPOOL_WELDING(JOINT_ID, REWORK_CODE, WELD_DATE, WELDER_ID, PASS_ID, WELD_PROCESS) " +
                                           "VALUES (:JOINT_ID, :REWORK_CODE, :WELD_DATE, :WELDER_ID, :PASS_ID, :WELD_PROCESS)";

                        cmd2.Parameters.Add("JOINT_ID", OracleType.Number);
                        cmd2.Parameters["JOINT_ID"].Value = dr["JOINT_ID"].ToString();

                        cmd2.Parameters.Add("REWORK_CODE", OracleType.VarChar);
                        cmd2.Parameters["REWORK_CODE"].Value = dr["REWORK_CODE"].ToString();

                        cmd2.Parameters.Add("WELD_DATE", OracleType.DateTime);
                        cmd2.Parameters["WELD_DATE"].Value = DateTime.Parse(dr["WELDED_DATE"].ToString()).ToString("dd-MMM-yyyy");

                        cmd2.Parameters.Add("WELDER_ID", OracleType.Number);
                        cmd2.Parameters["WELDER_ID"].Value = dr["WELDER_ID"].ToString();

                        string work_on = dr["WORK_ON"].ToString();
                        string pass_id = "1";

                        if (work_on == "R" || work_on == "RF")
                        {
                            pass_id = "1";
                        }
                        else
                        {
                            pass_id = "4"; // F
                        }
                        cmd2.Parameters.Add("PASS_ID", OracleType.Number);
                        cmd2.Parameters["PASS_ID"].Value = pass_id;

                        cmd2.Parameters.Add("WELD_PROCESS", OracleType.VarChar);
                        cmd2.Parameters["WELD_PROCESS"].Value = dr["WELD_PROCESS"].ToString();

                        cmd2.ExecuteNonQuery(); // welding details

                        // RF Case
                        if (work_on == "RF")
                        {
                            cmd2.Parameters["PASS_ID"].Value = 4;
                            cmd2.ExecuteNonQuery();
                        }
                    } // while
                }     // dr
            }         // welder details added
        }

        Master.ShowSuccess("Field Welding data imported!");
    }
    public void createTable_NEW_QR(string FileName, int spl_id, string id_1)
    {
        System.Text.Encoding enc = new System.Text.UTF8Encoding(true, true);

        //Get the BOM
        byte[] bom = enc.GetPreamble();

        //Get the raw bytes for the string
        byte[] bytes = enc.GetBytes("");

        //Combine the byte arrays
        byte[] final = new byte[bom.Length + bytes.Length];
        System.Buffer.BlockCopy(bom, 0, final, 0, bom.Length);
        System.Buffer.BlockCopy(bytes, 0, final, bom.Length, bytes.Length);

        var r = new Rectangle(160, 100)
        {
            //BackgroundColor=new BaseColor(179,227,238), remove this in original code
            Border = 0
        };


        Document dc = new Document(r, 0, 0, 0, 0);

        // PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + spl_id + ".pdf", FileMode.Create));

        PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create));

        dc.Open();

        // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);

        BaseFont customfont = BaseFont.CreateFont();
        int      a          = spl_id;

        //string connectionString = "Data Source=ALRAR;Persist Security Info=True;User ID=AMOGH;Password=ALRAR2020;Unicode=True";

        OracleConnection conn = WebTools.GetIpmsConnection();

        // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id;

        string query = "SELECT mat_code1,heat_no,nvl(paint_code,'NA')  as paint_code,wall_thk,joint_thk,size1,nvl(mat_type,'XXX') as mat_type,substr(mat_descr,1,100) AS mat_descr, SubStr(mat_descr,101,100) AS mat_descr2, SubStr(mat_descr,201,100) AS mat_descr3 FROM  view_bulk_paint_barcode WHERE spl_id=" + spl_id;


        OracleCommand cmd = new OracleCommand(query, conn);

        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }


        OracleDataReader rdr = cmd.ExecuteReader();
        // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL);
        Font bigFont      = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 8, Font.BOLD, BaseColor.BLACK);
        Font smallFont    = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK);
        Font mediumFont   = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 6, Font.BOLD, BaseColor.BLACK);
        Font mediumFont_a = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 4, Font.BOLD, BaseColor.BLACK);
        Font headfont     = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD);

        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;


        //table.AddCell(new Paragraph("Item code:" + rdr[0].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Paint Code:" + rdr[2].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Heat No:" + rdr[1].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Sch & Thk:" + rdr[3].ToString() + " & " + rdr[4].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Pipe-Size:" + rdr[5].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Main-Mat:" + rdr[6].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Pipe-Description:" + rdr[7].ToString(), mediumFont_a));
        //table.AddCell(new Paragraph(rdr[8].ToString(), mediumFont_a));
        //table.AddCell(new Paragraph(rdr[9].ToString(), mediumFont_a));


        rdr.Read();
        string s1 = "Item-Code / Paint-Code :" + "  " + rdr[0].ToString() + "/" + rdr[2].ToString();
        string s2 = "  " + "Heat-No / Sch &Thk :" + " " + rdr[1].ToString() + "/" + rdr[3].ToString() + " & " + rdr[4].ToString();
        string s3 = "  " + "Pipe-Size / Main-Mat :" + rdr[5].ToString() + "/" + rdr[6].ToString();
        string s4 = "  " + "Pipe-Description :" + rdr[7].ToString();

        BarcodeQRCode bcd = new BarcodeQRCode(s1.ToString() + "    " + s2.ToString() + "    " + s3.ToString() + "    " + s4.ToString(), 10, 10, null);

        PdfPTable table = new PdfPTable(2);

        table.SetWidthPercentage(new float[] { 70, 70 }, r);
        //table.SetWidths(new float[] { 145, 80 });
        table.SetWidths(new float[] { 100, 80 });
        table.DefaultCell.Border = Rectangle.NO_BORDER;
        table.DefaultCell.NoWrap = true;

        // PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh"));
        //PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / JI-2014", headfont));
        PdfPCell cell = new PdfPCell();

        cell.Image = iTextSharp.text.Image.GetInstance(bcd.GetImage());


        cell.Colspan             = 2;
        cell.Border              = 0;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell);


        conn.Close();
        dc.Add(table);
        dc.Close();



        //Barcode128 bc = new Barcode128();
        //bc.ChecksumText = true;
        //bc.Code = a.ToString().PadLeft(16, '0');
        //bc.Size = 4;
        //bc.BarHeight = 15;
        //bc.Baseline = 4;
        //PdfPTable table = new PdfPTable(2);
        //// table.SetWidths(new float[]{158,68});
        //table.SetWidthPercentage(new float[] { 100, 100 }, r);
        //table.SetWidths(new float[] { 145, 80 });
        //table.DefaultCell.Border = Rectangle.NO_BORDER;
        //table.DefaultCell.NoWrap = true;
        //// PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh"));
        //PdfPCell cell = new PdfPCell(new Paragraph("Job: Petrofac/JI-2037", headfont));
        //cell.Colspan = 2;
        //cell.Rowspan = 4;
        //cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        //cell.Border = 0;
        //cell.Padding = 4;
        //table.AddCell(cell);
        //cell = new PdfPCell();
        //cell.Image = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null));
        //cell.Colspan = 2;
        //cell.Border = 0;
        //cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        //table.AddCell(cell);
        //rdr.Read();


        //table.AddCell(new Paragraph("Item code:" + rdr[0].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Paint Code:" + rdr[2].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Heat No:" + rdr[1].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Sch & Thk:" + rdr[3].ToString() + " & " + rdr[4].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Pipe-Size:" + rdr[5].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Main-Mat:" + rdr[6].ToString(), mediumFont));
        //table.AddCell(new Paragraph("Pipe-Description:" + rdr[7].ToString(), mediumFont_a));
        //table.AddCell(new Paragraph(rdr[8].ToString(), mediumFont_a));
        //table.AddCell(new Paragraph(rdr[9].ToString(), mediumFont_a));



        //table.AddCell("");
        ////NEW  CONDITION
        //rdr.Close();
        ////END
        //conn.Close();
        //dc.Add(table);
        //dc.Close();
    }
    public void createTable(string FileName, int joint_d, string id_1)
    {
        var r = new Rectangle(220, 144)
        {
            //BackgroundColor=new BaseColor(179,227,238), remove this in original code
            Border = 0
        };
        Document dc = new Document(r, 0, 0, 0, 0);
        // PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + spl_id + ".pdf", FileMode.Create));

        PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create));

        dc.Open();
        // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
        BaseFont customfont = BaseFont.CreateFont();
        int      a          = joint_d;
        //string connectionString = "Data Source=ALRAR;Persist Security Info=True;User ID=AMOGH;Password=ALRAR2020;Unicode=True";
        OracleConnection conn = WebTools.GetIpmsConnection();
        // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id;
        string        query = "SELECT * FROM VIEW_BC_IMAGE_DETAIL_FLANGE WHERE JOINT_ID=" + joint_d;
        OracleCommand cmd   = new OracleCommand(query, conn);

        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        OracleDataReader rdr = cmd.ExecuteReader();
        // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL);
        Font bigFont   = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 8, Font.BOLD, BaseColor.BLACK);
        Font smallFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK);
        Font headfont  = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD);

        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
        Barcode128 bc = new Barcode128();

        bc.ChecksumText = true;
        bc.Code         = a.ToString().PadLeft(16, '0');
        bc.Size         = 4;
        bc.BarHeight    = 15;
        bc.Baseline     = 4;
        PdfPTable table = new PdfPTable(2);

        // table.SetWidths(new float[]{158,68});
        table.SetWidthPercentage(new float[] { 100, 100 }, r);
        table.SetWidths(new float[] { 145, 80 });
        table.DefaultCell.Border = Rectangle.NO_BORDER;
        table.DefaultCell.NoWrap = true;
        // PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh"));
        PdfPCell cell = new PdfPCell(new Paragraph("Job: BIFP/P11570", headfont));

        cell.Colspan             = 2;
        cell.Rowspan             = 4;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        cell.Border  = 0;
        cell.Padding = 4;
        table.AddCell(cell);
        cell = new PdfPCell();
        rdr.Read();
        string iso = rdr[0].ToString();
        string jnt = rdr[2].ToString();

        // bc.AltText = iso + spl;
        cell.Image = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null));

        cell.Colspan             = 2;
        cell.Border              = 0;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell);

        table.AddCell(new Paragraph("Iso:" + rdr[0].ToString(), smallFont));
        table.AddCell(new Paragraph("Rev:" + rdr[1].ToString(), bigFont));
        table.AddCell(new Paragraph("Joint-No:" + rdr[2].ToString(), bigFont));
        table.AddCell(new Paragraph("Joint-Size:" + rdr[4].ToString(), bigFont));
        table.AddCell(new Paragraph("Wbs-No:" + rdr[5].ToString(), bigFont));
        table.AddCell(new Paragraph("bolt-qty:" + rdr[6].ToString(), bigFont));
        table.AddCell(new Paragraph("Main Mat:" + rdr[7].ToString(), bigFont));
        table.AddCell(new Paragraph("Unit:" + rdr[9].ToString(), bigFont));
        table.AddCell(new Paragraph("Line:" + rdr[8].ToString(), smallFont));
        //   table.AddCell(new Paragraph("UniqueNo:" + rdr[9].ToString(), smallFont));
        table.AddCell("");
        //NEW  CONDITION
        rdr.Close();

        //END
        conn.Close();
        dc.Add(table);
        dc.Close();
    }
    //public void createTable_QR(string FileName, int spl_id, string id_1)
    //{
    //    //PdfPTable table = new PdfPTable(8);

    //    //PdfPCell cell;

    //    //cell = new PdfPCell();
    //    ////cell.setRowspan(2);
    //    //cell.Rowspan = 2;
    //    //table.AddCell(cell);

    //    //for (int aw = 0; aw < 8; aw++)
    //    //{
    //    //    table.AddCell("hi");
    //    //}


    //    System.Text.Encoding enc = new System.Text.UTF8Encoding(true, true);

    //    //Get the BOM
    //    byte[] bom = enc.GetPreamble();

    //    //Get the raw bytes for the string
    //    byte[] bytes = enc.GetBytes("");


    //    //Combine the byte arrays
    //    byte[] final = new byte[bom.Length + bytes.Length];
    //    System.Buffer.BlockCopy(bom, 0, final, 0, bom.Length);
    //    System.Buffer.BlockCopy(bytes, 0, final, bom.Length, bytes.Length);

    //    var r = new Rectangle(165, 71)
    //    {
    //        //BackgroundColor=new BaseColor(179,227,238), remove this in original code
    //        Border = 0
    //    };

    //    Document dc = new Document(r, 0, 0, 0, 0);



    //    PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create));

    //    dc.Open();

    //    // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
    //    BaseFont customfont = BaseFont.CreateFont();
    //    int a = spl_id;
    //    string connectionString = WebTools.GetIpmsConnection().ConnectionString;
    //    OracleConnection conn = new OracleConnection(connectionString);
    //    // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id;
    //    string query = "SELECT iso_title1,spl_rev,spool,spl_size,area_l1,weight,unit,mat_type,line_no FROM view_bc_image_dt WHERE spl_id=" + spl_id;
    //    OracleCommand cmd = new OracleCommand(query, conn);
    //    conn.Open();
    //    OracleDataReader rdr = cmd.ExecuteReader();
    //    // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL);
    //    Font bigFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 6.3f, Font.BOLD, BaseColor.BLACK);
    //    Font headfont = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD);
    //    iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;


    //    rdr.Read();

    //    string qrstring = rdr[0].ToString() + " / " + rdr[2].ToString();

    //    BarcodeQRCode bcd = new BarcodeQRCode(qrstring.ToString(), 7000, 7000, null);



    //    // a table with three columns
    //    PdfPTable table_100 = new PdfPTable(2);
    //    //  table_100.SetWidthPercentage(new float[] { 40, 120 }, r);
    //    //  table_100.SetWidths(new float[] { 50, 120 });

    //    table_100.SetWidthPercentage(new float[] { 75, 100 }, r);
    //    table_100.SetWidths(new float[] { 75, 100 });
    //    table_100.DefaultCell.Border = Rectangle.NO_BORDER;
    //    // the cell object
    //    PdfPCell cell_100 = new PdfPCell();

    //    table_100.HorizontalAlignment = Element.ALIGN_LEFT;

    //    cell_100.Border = 0;
    //    cell_100.PaddingTop = 3;

    //    cell_100.Image = iTextSharp.text.Image.GetInstance(bcd.GetImage());

    //    cell_100.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right

    //    table_100.AddCell(cell_100);

    //    //var splitter =  "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Spool:" + rdr[2].ToString();

    //    var splitter = "Line No :" + rdr[8].ToString() + "\n" + "\n" + "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Spool:" + rdr[2].ToString() + "\n" + "\n" + "Weight:" + rdr[5].ToString();

    //    var splitter1 = splitter.Split('_');


    //    //var splitter1 = splitter.Split('_');

    //    iTextSharp.text.Paragraph paragraph;
    //    paragraph = new Paragraph();

    //    paragraph.Add(new Chunk(ConvertStringArrayToString(splitter1), bigFont));
    //    cell_100 = new PdfPCell(paragraph);
    //    cell_100.PaddingTop = 8;
    //    cell_100.Border = 0;

    //    table_100.AddCell(cell_100);

    //    //table_100.AddCell(new Paragraph(ConvertStringArrayToString(splitter1), bigFont));

    //    conn.Close();
    //    dc.Add(table_100);
    //    dc.Close();



    //}

    public void createTable_QR(string FileName, int joint_id, string id_1)
    {
        System.Text.Encoding enc = new System.Text.UTF8Encoding(true, true);

        //Get the BOM
        byte[] bom = enc.GetPreamble();

        //Get the raw bytes for the string
        byte[] bytes = enc.GetBytes("");


        //Combine the byte arrays
        byte[] final = new byte[bom.Length + bytes.Length];
        System.Buffer.BlockCopy(bom, 0, final, 0, bom.Length);
        System.Buffer.BlockCopy(bytes, 0, final, bom.Length, bytes.Length);

        var r = new Rectangle(216, 144)
                //var r = new Rectangle(216, 144)
        {
            //BackgroundColor=new BaseColor(179,227,238), remove this in original code
        };
        Document dc = new Document(r, 0, 0, 0, 0);

        PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create));

        dc.Open();


        BaseFont         customfont = BaseFont.CreateFont();
        int              a          = joint_id;
        OracleConnection conn       = WebTools.GetIpmsConnection();
        // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id;
        string        query = "SELECT * FROM VIEW_BC_IMAGE_DETAIL_FLANGE WHERE JOINT_ID=" + joint_id;
        OracleCommand cmd   = new OracleCommand(query, conn);

        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        OracleDataReader rdr = cmd.ExecuteReader();
        // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL);
        Font bigFont = FontFactory.GetFont("Arial", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK);


        Font headfont = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD);

        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;


        rdr.Read();

        string qrstring = rdr[0].ToString() + " / " + rdr[2].ToString();

        BarcodeQRCode bcd = new BarcodeQRCode(qrstring.ToString(), 300, 300, null);

        // a table with three columns
        PdfPTable table_100 = new PdfPTable(2);

        //  table_100.SetWidthPercentage(new float[] { 40, 120 }, r);
        //  table_100.SetWidths(new float[] { 50, 120 });

        table_100.SetWidthPercentage(new float[] { 90, 170 }, r);
        table_100.SetWidths(new float[] { 90, 170 });


        Font     headerFont = new Font(Font.FontFamily.COURIER, 15f, Font.BOLD);
        PdfPCell cell       = new PdfPCell(new Paragraph("Job: BIFP/P11570", headerFont));

        cell.Colspan = 2;

        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        cell.Border = 0;


        table_100.AddCell(cell);

        // the cell object
        PdfPCell cell_100 = new PdfPCell();

        table_100.HorizontalAlignment = Element.ALIGN_LEFT;

        cell_100.Border       = 0;
        cell_100.PaddingTop   = 10;
        cell_100.PaddingRight = 0;

        cell_100.Image = iTextSharp.text.Image.GetInstance(bcd.GetImage());

        cell_100.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right

        table_100.AddCell(cell_100);

        //var splitter =  "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Spool:" + rdr[2].ToString();

        //var splitter = "\n" + "\n"+"Iso:" + rdr[0].ToString() + "\n" + "\n" + "Joint:" + rdr[2].ToString() + "\n" + "\n" + "Joint size:" + rdr[4].ToString();
        var splitter  = "Line No:" + rdr[8].ToString() + "\n" + "\n" + "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Joint:" + rdr[2].ToString() + "\n" + "\n" + "Joint size:" + rdr[4].ToString() + "\n" + "\n" + "Item Code1:" + rdr[11].ToString() + "\n" + "\n" + "Item Code2:" + rdr[12].ToString();
        var splitter1 = splitter.Split('_');


        //var splitter1 = splitter.Split('_');

        iTextSharp.text.Paragraph paragraph;
        paragraph = new Paragraph();

        paragraph.Add(new Chunk(ConvertStringArrayToString(splitter1), bigFont));
        cell_100             = new PdfPCell(paragraph);
        cell_100.PaddingTop  = 15;
        cell_100.PaddingLeft = 0;
        cell_100.Border      = 0;

        table_100.AddCell(cell_100);

        //table_100.AddCell(new Paragraph(ConvertStringArrayToString(splitter1), bigFont));

        conn.Close();
        dc.Add(table_100);
        dc.Close();
    }
    public void createTable(string FileName, int mat_id, string id_1)
    {
        //72 point =1 inch
        //
        // var r = new iTextSharp.text.Rectangle(220, 144)
        var r = new iTextSharp.text.Rectangle(144, 72)
        {
            //BackgroundColor=new BaseColor(179,227,238), remove this in original code
            Border = 0
        };
        Document dc = new Document(r, 0, 0, 0, 0);
        // PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + spl_id + ".pdf", FileMode.Create));

        PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create));

        dc.Open();
        // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
        BaseFont customfont = BaseFont.CreateFont();
        int      a          = mat_id;
        //string connectionString = "Data Source=ALRAR;Persist Security Info=True;User ID=AMOGH;Password=ALRAR2020;Unicode=True";
        OracleConnection conn = WebTools.GetIpmsConnection();
        // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id;
        string        query = "SELECT mat_code1,mat_code2,size_desc,THK1, ITEM_NAM FROM view_stock WHERE mat_id=" + mat_id;
        OracleCommand cmd   = new OracleCommand(query, conn);

        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        OracleDataReader rdr = cmd.ExecuteReader();
        // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL);
        Font bigFont   = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 8, Font.BOLD, BaseColor.BLACK);
        Font smallFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK);
        Font headfont  = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD);

        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
        Barcode128 bc = new Barcode128();

        bc.ChecksumText = true;
        bc.Code         = a.ToString().PadLeft(16, '0');
        bc.Size         = 4;
        bc.BarHeight    = 25;

        bc.Baseline = 4;



        PdfPTable table = new PdfPTable(2);

        // table.SetWidths(new float[]{158,68});
        table.SetWidthPercentage(new float[] { 100, 100 }, r);
        table.SetWidths(new float[] { 144, 72 });
        table.DefaultCell.Border = Rectangle.NO_BORDER;
        table.DefaultCell.NoWrap = true;

        // PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh"));
        PdfPCell cell = new PdfPCell(new Paragraph());

        cell.Colspan             = 2;
        cell.Rowspan             = 4;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        cell.Border  = 0;
        cell.Padding = 4;
        table.AddCell(cell);
        cell = new PdfPCell();
        //cell.Image = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null));
        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null));
        img.ScaleToFit(r);
        cell.Colspan             = 2;
        cell.Border              = 0;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell);
        rdr.Read();
        table.AddCell(new Paragraph("Mat Code1:" + rdr[0].ToString(), smallFont));
        //    table.AddCell(new Paragraph("MESC Code:" + rdr[1].ToString(), bigFont));
        //    table.AddCell(new Paragraph("Size:" + rdr[2].ToString(), bigFont));
        //    table.AddCell(new Paragraph("Thk/Sch:" + rdr[3].ToString(), bigFont));
        //    table.AddCell(new Paragraph("Description:" + rdr[4].ToString(), bigFont));
        table.AddCell("");
        //NEW  CONDITION
        rdr.Close();
        //END
        conn.Close();
        dc.Add(img);
        dc.Close();

        Response.Write(bc.BarcodeSize.ToString());
    }
    public static void ExportToCSV(string query, string fileName)
    {
        //Add Response header
        HttpResponse Response = HttpContext.Current.Response;

        Response.Clear();
        Response.AddHeader("content-disposition",
                           string.Format("attachment;filename={0}.csv", fileName));
        Response.Charset     = "";
        Response.ContentType = "application/vnd.xls";
        //GET Data From Database

        OracleConnection cn  = WebTools.GetIpmsConnection();
        OracleCommand    cmd = new OracleCommand(query, cn);

        cmd.CommandTimeout = 999999;
        cmd.CommandType    = CommandType.Text;
        try
        {
            //cn.Open();
            OracleDataReader dr = cmd.ExecuteReader();
            StringBuilder    sb = new StringBuilder();

            //CSV Header
            for (int count = 0; count < dr.FieldCount; count++)
            {
                if (dr.GetName(count) != null)
                {
                    sb.Append(dr.GetName(count));
                }
                if (count < dr.FieldCount - 1)
                {
                    sb.Append(",");
                }
            }
            Response.Write(sb.ToString() + "\n");
            Response.Flush();

            //CSV Body
            while (dr.Read())
            {
                sb = new StringBuilder();

                for (int col = 0; col < dr.FieldCount - 1; col++)
                {
                    if (!dr.IsDBNull(col))
                    {
                        if (dr.GetDataTypeName(col).ToUpper() == "DATE")
                        {
                            sb.Append(DateTime.Parse(dr.GetValue(col).ToString()).ToString("dd-MMM-yyyy"));
                        }
                        else
                        {
                            sb.Append(dr.GetValue(col).ToString().Replace(",", " "));
                        }
                    }
                    sb.Append(",");
                }

                if (!dr.IsDBNull(dr.FieldCount - 1))
                {
                    if (!dr.IsDBNull(dr.FieldCount - 1))
                    {
                        if (dr.GetDataTypeName(dr.FieldCount - 1).ToUpper() == "DATE")
                        {
                            sb.Append(DateTime.Parse(dr.GetValue(dr.FieldCount - 1).ToString()).ToString("dd-MMM-yyyy"));
                        }
                        else
                        {
                            sb.Append(dr.GetValue(dr.FieldCount - 1).ToString().Replace(",", " "));
                        }
                    }
                }

                Response.Write(sb.ToString() + "\n");
                Response.Flush();
            }
            dr.Dispose();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
            cmd.Connection.Close();
            cn.Close();
        }
        Response.End();
    }
    public static void ImportDataTable(DataTable data, string TableName, string TablePk, string ProjIdField, string ProjIdValue)
    {
        DataTable dt = new DataTable();

        dt = data;

        bool has_pj_id = string.IsNullOrEmpty(ProjIdField) ? false : true;

        bool   first_col = true;
        string sql       = "INSERT " +
                           (string.IsNullOrEmpty(TablePk) ? "" : string.Format(@"/*+ IGNORE_ROW_ON_DUPKEY_INDEX({0},{1}) */", TableName, TablePk)) +
                           " INTO " + TableName + " (";

        // add proj_id field
        if (has_pj_id)
        {
            sql      += ProjIdField;
            first_col = false;
        }

        foreach (DataColumn col in dt.Columns)
        {
            if (!first_col)
            {
                sql += ",";
            }
            else
            {
                first_col = false;
            }

            sql += col.ColumnName;
        }

        sql      += ") VALUES (";
        first_col = true;

        // add proj_id field
        if (has_pj_id)
        {
            sql      += ":" + ProjIdField;
            first_col = false;
        }

        foreach (DataColumn col in dt.Columns)
        {
            if (!first_col)
            {
                sql += ",";
            }
            else
            {
                first_col = false;
            }

            sql += ":" + col.ColumnName;
        }

        sql += ")";

        using (OracleConnection conn = WebTools.GetIpmsConnection()) // will open connection too
        {
            List <TableFieldInfo> columns = GetColumns(conn, TableName);
            OracleCommand         cmd     = new OracleCommand(sql, conn);

            for (int rowindex = 1; rowindex < dt.Rows.Count; rowindex++) // row 0 is heading
            {
                DataRow row = dt.Rows[rowindex];
                cmd.Parameters.Clear();

                // add proj_id value
                if (has_pj_id)
                {
                    OracleParameter proj_par = new OracleParameter(ProjIdField, ProjIdValue);
                    cmd.Parameters.Add(proj_par);
                }

                foreach (DataColumn col in dt.Columns)
                {
                    string data_type = columns.Where(x => x.FieldName == col.ColumnName).First().FieldDataType;
                    int    data_len  = columns.Where(x => x.FieldName == col.ColumnName).First().FieldSize;

                    string col_val = row[col].ToString().Trim();

                    if (data_type.ToLower().Contains("date"))
                    {
                        DateTime value;
                        if (DateTime.TryParse(col_val, out value))
                        {
                            col_val = value.ToString("dd-MMM-yyyy");
                            //col_val = "";
                        }
                        else
                        {
                            col_val = "";
                        }
                    }
                    else if (data_type.ToLower().Contains("varchar"))
                    {
                        if (col_val.Length > data_len)
                        {
                            col_val = col_val.Substring(0, data_len);
                        }
                    }


                    OracleParameter parm = new OracleParameter(col.ColumnName, col_val);
                    cmd.Parameters.Add(parm);
                }

                cmd.ExecuteNonQuery();
            }

            cmd.Dispose();
        }
    }
    public static void Import_Excel_File(string FilePath, string Extension, string TableName, string TablePk, string ProjIdField, string ProjIdValue)
    {
        string conStr = "";

        switch (Extension)
        {
        case ".xls":     //Excel 97-03
            conStr = ConnStrHelper.Excel03ConString();
            break;

        case ".xlsx":     //Excel 07
            conStr = ConnStrHelper.Excel07ConString();
            break;

        default:
            return;     // not supported
        }

        conStr = String.Format(conStr, FilePath, "Yes");
        OleDbConnection  connExcel = new OleDbConnection(conStr);
        OleDbCommand     cmdExcel  = new OleDbCommand();
        OleDbDataAdapter oda       = new OleDbDataAdapter();
        DataTable        dt        = new DataTable();

        cmdExcel.Connection = connExcel;

        //Get the name of First Sheet
        connExcel.Open();
        DataTable dtExcelSchema;

        dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();

        connExcel.Close();

        //Read Data from First Sheet
        connExcel.Open();
        cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
        oda.SelectCommand    = cmdExcel;
        oda.Fill(dt);
        connExcel.Close();

        bool has_pj_id = string.IsNullOrEmpty(ProjIdField) ? false : true;

        bool   first_col = true;
        string sql       = "INSERT " +
                           (string.IsNullOrEmpty(TablePk) ? "" : string.Format(@"/*+ IGNORE_ROW_ON_DUPKEY_INDEX({0},{1}) */", TableName, TablePk)) +
                           " INTO " + TableName + " (";

        // add proj_id field
        if (has_pj_id)
        {
            sql      += ProjIdField;
            first_col = false;
        }

        foreach (DataColumn col in dt.Columns)
        {
            if (!first_col)
            {
                sql += ",";
            }
            else
            {
                first_col = false;
            }

            sql += col.ColumnName;
        }

        sql      += ") VALUES (";
        first_col = true;

        // add proj_id field
        if (has_pj_id)
        {
            sql      += ":" + ProjIdField;
            first_col = false;
        }

        foreach (DataColumn col in dt.Columns)
        {
            if (!first_col)
            {
                sql += ",";
            }
            else
            {
                first_col = false;
            }

            sql += ":" + col.ColumnName;
        }

        sql += ")";

        using (OracleConnection conn = WebTools.GetIpmsConnection()) // will open connection too
        {
            OracleCommand cmd = new OracleCommand(sql, conn);

            foreach (DataRow row in dt.Rows)
            {
                cmd.Parameters.Clear();

                // add proj_id value
                if (has_pj_id)
                {
                    OracleParameter proj_par = new OracleParameter(ProjIdField, ProjIdValue);
                    cmd.Parameters.Add(proj_par);
                }

                foreach (DataColumn col in dt.Columns)
                {
                    string col_val = row[col].ToString();

                    if (col.ColumnName.ToUpper().Contains("DATE") && !string.IsNullOrEmpty(col_val))
                    {
                        DateTime value;
                        if (DateTime.TryParse(col_val, out value))
                        {
                            col_val = value.ToString("dd-MMM-yyyy");
                        }
                        else
                        {
                            col_val = "";
                        }
                    }

                    OracleParameter parm = new OracleParameter(col.ColumnName, col_val);
                    cmd.Parameters.Add(parm);
                }
                cmd.ExecuteNonQuery();
            }

            cmd.Dispose();
        }

        //Bind Data to GridView
        //GridView1.Caption = Path.GetFileName(FilePath);
        //jointsGridView.DataSource = dt;
        //jointsGridView.DataBind();
    }
    private void CollectPDFs(ZipFile zip_file)
    {
        //string path = WebTools.SessionDataPath();
        string sql        = "";
        string FileName   = "";
        string folderPath = WebTools.GetExpr("path", "dir_objects", " dir_obj='ISO_SPOOLGEN'");
        string filePath   = string.Empty;

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            //Isometric
            sql = "SELECT * FROM VIEW_ISO_PDF_BLOB_WO_MIV WHERE ISSUE_ID=" + mivGridView.SelectedValue.ToString();
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["PDF_FILE_NAME"];
                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }
                        if (File.Exists(folderPath + dataReader["PDF_FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["PDF_FILE_NAME"]);
                        }
                    }
                } //OracleDataReader1
            }     //OracleCommand1

            //Spool Piece
            sql        = "SELECT * FROM VIEW_SPOOL_PDF_WO_MIV WHERE ISSUE_ID=" + mivGridView.SelectedValue.ToString();
            folderPath = WebTools.GetExpr("path", "dir_objects", " dir_obj='SPL_SPOOLGEN'");
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["PDF_FILE_NAME"];
                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }
                        if (File.Exists(folderPath + dataReader["PDF_FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["PDF_FILE_NAME"]);
                        }
                    }
                } //OracleDataReader2
            }     //OracleCommand2

            // Iso As Built
            sql        = "SELECT * FROM VIEW_ISO_PDF_BLOB_WO_MIV WHERE ISSUE_ID=" + mivGridView.SelectedValue.ToString();
            folderPath = WebTools.GetExpr("path", "dir_objects", " dir_obj='ISO_AB'");
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["PDF_FILE_NAME"];
                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }
                        if (File.Exists(folderPath + dataReader["PDF_FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["PDF_FILE_NAME"]);
                        }
                    }
                } //OracleDataReader2
            }     //OracleCommand2
        }         //OracleConnection
    }
Пример #28
0
    private void CollectPDFs(ZipFile zip_file)
    {
        //string path = WebTools.SessionDataPath();
        string sql        = "";
        string FileName   = "";
        string folderPath = WebTools.GetExpr("path", "dir_objects", " dir_obj='ISO_SPOOLGEN'");
        string filePath   = string.Empty;

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            //Isometric
            sql = "SELECT * FROM VIEW_ISO_PDF_BLOB_WO WHERE WO_ID=" + jcGridView.SelectedValue.ToString();
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["PDF_FILE_NAME"];

                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }

                        //if (dataReader["SG_PDF_BLOB"] == DBNull.Value) continue;

                        //byte[] byteArray = (Byte[])dataReader["SG_PDF_BLOB"];

                        if (File.Exists(folderPath + dataReader["PDF_FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["PDF_FILE_NAME"]);
                        }
                    }
                } //OracleDataReader1
            }     //OracleCommand1

            //Spool Piece
            sql        = "SELECT * FROM VIEW_SPOOL_PDF_WO WHERE WO_ID=" + jcGridView.SelectedValue.ToString();
            folderPath = WebTools.GetExpr("path", "dir_objects", " dir_obj='SPL_SPOOLGEN'");
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["PDF_FILE_NAME"];

                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }

                        //if (dataReader["SG_PDF_BLOB"] == DBNull.Value) continue;

                        //byte[] byteArray = (Byte[])dataReader["SG_PDF_BLOB"];
                        //using (FileStream fs = new FileStream(FileName, FileMode.CreateNew, FileAccess.Write))
                        //{
                        //    fs.Write(byteArray, 0, byteArray.Length);
                        //    zip_file.AddFile(FileName, "SPOOL");
                        //}

                        if (File.Exists(folderPath + dataReader["PDF_FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["PDF_FILE_NAME"]);
                        }
                    }
                } //OracleDataReader2
            }     //OracleCommand2

            // Iso AS Built
            sql        = "SELECT * FROM VIEW_ISO_PDF_BLOB_WO WHERE WO_ID=" + jcGridView.SelectedValue.ToString();
            folderPath = WebTools.GetExpr("path", "dir_objects", " dir_obj='ISO_AB'");
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        FileName = WebTools.SessionDataPath() + dataReader["PDF_FILE_NAME"];

                        if (File.Exists(FileName))
                        {
                            File.Delete(FileName);
                        }
                        if (File.Exists(folderPath + dataReader["PDF_FILE_NAME"]))
                        {
                            zip_file.AddFile(folderPath + dataReader["PDF_FILE_NAME"]);
                        }
                    }
                }
            }
        }//OracleConnection
    }
Пример #29
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string po_id = WebTools.GetExpr("PO_ID", "PIP_PO", "PROJECT_ID=" + Session["PROJECT_ID"].ToString() + " AND PO_NO='" + PO_NO_HiddenField.Value + "'");

        if (po_id.Length == 0)
        {
            Master.ShowWarn("PO Number not found!");
            return;
        }

        string FileName = WebTools.SessionDataPath() + txtTC_No.Text.Replace("/", "-") + ".pdf";

        if (File.Exists(FileName))
        {
            System.IO.File.Delete(FileName);
        }
        if (PDF_Upload.HasFile == true)
        {
            PDF_Upload.SaveAs(FileName);
        }

        //Saving to Oracle

        byte[] byteArray = null;

        if (PDF_Upload.HasFile == true)
        {
            using (FileStream fs = new FileStream
                                       (FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                byteArray = new byte[fs.Length];

                int iBytesRead = fs.Read(byteArray, 0, (int)fs.Length);
            }
        }

        string sql = " INSERT INTO PIP_TEST_CARDS (PROJECT_ID, TC_CODE, REMARKS, PO_ID, MTC_BLOB) VALUES (:PROJECT_ID, :TC_CODE, :REMARKS, :PO_ID, :MTC_BLOB)";

        using (OracleConnection conn = WebTools.GetIpmsConnection())
        {
            //conn.Open();

            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                cmd.Parameters.Add("PROJECT_ID", OracleType.Number);
                cmd.Parameters[0].Value = Session["PROJECT_ID"].ToString();

                cmd.Parameters.Add("TC_CODE", OracleType.VarChar);
                cmd.Parameters[1].Value = txtTC_No.Text;

                cmd.Parameters.Add("REMARKS", OracleType.VarChar);
                cmd.Parameters[2].Value = txtRemarks.Text;

                cmd.Parameters.Add("PO_ID", OracleType.Number);
                cmd.Parameters[3].Value = po_id;

                cmd.Parameters.Add("MTC_BLOB", OracleType.Blob);
                if (byteArray != null)
                {
                    cmd.Parameters[4].Value = byteArray;
                }
                else
                {
                    cmd.Parameters[4].Value = DBNull.Value;
                }

                cmd.ExecuteNonQuery();
            }
            Master.ShowMessage(txtTC_No.Text + " Saved!");
        }
    }
    public static void ExportToExcelNopi(string FilePath, string SqlQuery)
    {
        DataTable dt = new DataTable();

        OracleConnection conn = WebTools.GetIpmsConnection();
        OracleCommand    cmd  = new OracleCommand(SqlQuery, conn);

        // create data adapter
        OracleDataAdapter da = new OracleDataAdapter(cmd);

        // this will query your database and return the result to your datatable
        da.Fill(dt);

        // close objects
        conn.Close();
        da.Dispose();
        cmd.Dispose();

        using (FileStream stream = new FileStream(FilePath, FileMode.Create, FileAccess.Write))
        {
            IWorkbook       wb    = new XSSFWorkbook();
            ISheet          sheet = wb.CreateSheet("Sheet1");
            ICreationHelper cH    = wb.GetCreationHelper();

            // create header
            IRow header_row = sheet.CreateRow(0); // first row = 0

            // style for heading
            IFont boldFont = wb.CreateFont();
            boldFont.Boldweight = (short)FontBoldWeight.Bold;
            ICellStyle header_style = wb.CreateCellStyle();
            header_style.SetFont(boldFont);

            //boldStyle.BorderBottom = BorderStyle.Medium;
            header_style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
            header_style.FillPattern         = FillPattern.SolidForeground;
            header_style.Alignment           = HorizontalAlignment.Center;
            header_style.VerticalAlignment   = VerticalAlignment.Center;

            for (int j = 0; j < dt.Columns.Count; j++)
            {
                ICell cell = header_row.CreateCell(j);
                cell.SetCellValue(cH.CreateRichTextString(dt.Columns[j].ColumnName));
                cell.CellStyle = header_style;
            }


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                IRow row = sheet.CreateRow(i + 1);
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    DataRow drow      = dt.Rows[i];
                    string  str_value = drow.ItemArray[j].ToString();
                    ICell   cell      = row.CreateCell(j);
                    if (dt.Columns[j].DataType == typeof(DateTime) && drow.ItemArray[j] != DBNull.Value)
                    {
                        cell.SetCellValue(DateTime.Now);
                        IDataFormat dataFormatCustom = wb.CreateDataFormat();

                        DateTime?date_field = drow.Field <DateTime?>(j);

                        //cell.CellStyle.DataFormat = dataFormatCustom.GetFormat("yyyyMMdd HH:mm:ss");
                        //DateTime.ParseExact(str_value, "dd/M/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)
                        cell.SetCellValue(date_field.Value);
                        ICellStyle date_style = wb.CreateCellStyle();
                        date_style.DataFormat = dataFormatCustom.GetFormat("dd-mmm-yyyy;@");
                        cell.CellStyle        = date_style;
                    }
                    {
                        cell.SetCellValue(cH.CreateRichTextString(str_value.ToString()));
                    }
                }
            }
            wb.Write(stream);
        }
    }