Created
October 22, 2011 00:18
-
-
Save octocat/1305321 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| #region Adornment Factory | |
| /// <summary> | |
| /// Establishes an <see cref="IAdornmentLayer"/> to place the adornment on and exports the <see cref="IWpfTextViewCreationListener"/> | |
| /// that instantiates the adornment on the event of a <see cref="IWpfTextView"/>'s creation | |
| /// </summary> |
ubuntong11-spec
commented
Dec 22, 2025
<title>តារាងពិនិត្យតាមដានសម្ភារនិងទ្រព្យសម្បត្តិរដ្ឋ</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Khmer:wght@400;600;700&display=swap');
</style>
<script>
const STORAGE_KEY = 'property-tracking-table-data-v2';
// ===============================
// គណនាសរុបសម្រាប់តារាងទូទៅ
// ===============================
function calculateTableTotals(bodyId, totalPrefix, numericColumns) {
const tbody = document.getElementById(bodyId);
if (!tbody) return;
const rows = tbody.querySelectorAll('tr');
const totals = {};
// Initialize totals
numericColumns.forEach(col => {
totals[col] = 0;
});
// Sum up values
rows.forEach(row => {
const cells = row.querySelectorAll('td');
numericColumns.forEach(colIndex => {
if (cells[colIndex]) {
const value = parseFloat(cells[colIndex].textContent) || 0;
totals[colIndex] += value;
}
});
});
// Update total row
numericColumns.forEach((colIndex, i) => {
const totalCell = document.getElementById(`${totalPrefix}_${i}`);
if (totalCell) {
totalCell.textContent = totals[colIndex];
}
});
}
// គណនាសរុបសម្រាប់តារាងដី (columns 2-12 are numeric)
function calculateLandTotals() {
calculateTableTotals('landBody', 'landTotal', [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
}
// គណនាសរុបសម្រាប់តារាងអគារ (columns 2-11 are numeric)
function calculateBuildingTotals() {
calculateTableTotals('buildingBody', 'buildingTotal', [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
}
// គណនាសរុបសម្រាប់តារាងបច្ចេកទេស (columns 2-8 are numeric)
function calculateTechnicalTotals() {
calculateTableTotals('technicalBody', 'technicalTotal', [2, 3, 4, 5, 6, 7, 8]);
}
// គណនាសរុបសម្រាប់តារាងយានយន្ត (columns 2-8 are numeric)
function calculateVehiclesTotals() {
calculateTableTotals('vehiclesBody', 'vehiclesTotal', [2, 3, 4, 5, 6, 7, 8]);
}
// គណនាសរុបសម្រាប់តារាងសម្ភារ (columns 2-8 are numeric)
function calculateSuppliesTotals() {
calculateTableTotals('suppliesBody', 'suppliesTotal', [2, 3, 4, 5, 6, 7, 8]);
}
// គណនាសរុបទាំងអស់
function calculateAllTotals() {
calculateLandTotals();
calculateBuildingTotals();
calculateTechnicalTotals();
calculateVehiclesTotals();
calculateSuppliesTotals();
alert('✅ បានគណនាសរុបរួចរាល់!');
}
// ===============================
// បន្ថែមជួរថ្មី
// ===============================
// បន្ថែមជួរដី
function addLandRow() {
const tbody = document.getElementById('landBody');
const rowCount = tbody.rows.length + 1;
const row = tbody.insertRow();
row.innerHTML = `
${rowCount}
0
0
0
0
0
0
0
0
0
0
0
លុប
`;
enableAutoCalculateForRow(row);
calculateLandTotals();
}
// បន្ថែមជួរអគារ
function addBuildingRow() {
const tbody = document.getElementById('buildingBody');
const rowCount = tbody.rows.length + 1;
const row = tbody.insertRow();
row.innerHTML = `
${rowCount}
0
0
0
0
0
0
0
0
0
0
លុប
`;
enableAutoCalculateForRow(row);
calculateBuildingTotals();
}
// បន្ថែមជួរបច្ចេកទេស
function addTechnicalRow() {
const tbody = document.getElementById('technicalBody');
const rowCount = tbody.rows.length + 1;
const row = tbody.insertRow();
row.innerHTML = `
${rowCount}
0
0
0
0
0
0
0
លុប
`;
enableAutoCalculateForRow(row);
calculateTechnicalTotals();
}
// បន្ថែមជួរយានយន្ត
function addVehiclesRow() {
const tbody = document.getElementById('vehiclesBody');
const rowCount = tbody.rows.length + 1;
const row = tbody.insertRow();
row.innerHTML = `
${rowCount}
0
0
0
0
0
0
0
លុប
`;
enableAutoCalculateForRow(row);
calculateVehiclesTotals();
}
// បន្ថែមជួរសម្ភារ
function addSuppliesRow() {
const tbody = document.getElementById('suppliesBody');
const rowCount = tbody.rows.length + 1;
const row = tbody.insertRow();
row.innerHTML = `
${rowCount}
0
0
0
0
0
0
0
លុប
`;
enableAutoCalculateForRow(row);
calculateSuppliesTotals();
}
// ===============================
// លុបជួរ
// ===============================
function deleteRow(btn, bodyId) {
if (confirm('តើអ្នកពិតជាចង់លុបជួរនេះមែនទេ?')) {
const row = btn.parentNode.parentNode;
const tbody = document.getElementById(bodyId);
row.remove();
// រៀបលេខរៀងឡើងវិញ
Array.from(tbody.rows).forEach((r, idx) => {
r.cells[0].innerHTML = idx + 1;
});
// គណនាសរុបឡើងវិញ
if (bodyId === 'landBody') calculateLandTotals();
else if (bodyId === 'buildingBody') calculateBuildingTotals();
else if (bodyId === 'technicalBody') calculateTechnicalTotals();
else if (bodyId === 'vehiclesBody') calculateVehiclesTotals();
else if (bodyId === 'suppliesBody') calculateSuppliesTotals();
}
}
// ===============================
// រក្សាទុកទិន្នន័យ
// ===============================
function saveData() {
try {
const data = {
// ព័ត៌មានក្បាល
authority: document.getElementById('authority').value,
unit: document.getElementById('unit').value,
user: document.getElementById('user').value,
school: document.getElementById('school').value,
dispute: document.getElementById('dispute').value,
// ទិន្នន័យតារាង
landBody: getTableData('landBody'),
buildingBody: getTableData('buildingBody'),
technicalBody: getTableData('technicalBody'),
vehiclesBody: getTableData('vehiclesBody'),
suppliesBody: getTableData('suppliesBody')
};
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
alert('✅ បានរក្សាទុកទិន្នន័យដោយជោគជ័យ!');
} catch (error) {
alert('❌ មានបញ្ហា: ' + error.message);
}
}
function getTableData(bodyId) {
const tbody = document.getElementById(bodyId);
const rows = [];
Array.from(tbody.rows).forEach(row => {
const rowData = [];
Array.from(row.cells).forEach((cell, index) => {
// មិនរក្សាទុក column សកម្មភាព (ប៊ូតុងលុប)
if (index < row.cells.length - 1) {
rowData.push(cell.innerText.trim());
}
});
rows.push(rowData);
});
return rows;
}
// ===============================
// ផ្ទុកទិន្នន័យ
// ===============================
function loadData() {
try {
const saved = localStorage.getItem(STORAGE_KEY);
if (!saved) {
console.log('មិនមានទិន្នន័យដែលបានរក្សាទុកទេ');
return;
}
const data = JSON.parse(saved);
// បំពេញព័ត៌មានក្បាល
if (data.authority) document.getElementById('authority').value = data.authority;
if (data.unit) document.getElementById('unit').value = data.unit;
if (data.user) document.getElementById('user').value = data.user;
if (data.school) document.getElementById('school').value = data.school;
if (data.dispute) document.getElementById('dispute').value = data.dispute;
// បំពេញតារាង
if (data.landBody) loadTableData('landBody', data.landBody, 14);
if (data.buildingBody) loadTableData('buildingBody', data.buildingBody, 14);
if (data.technicalBody) loadTableData('technicalBody', data.technicalBody, 11);
if (data.vehiclesBody) loadTableData('vehiclesBody', data.vehiclesBody, 11);
if (data.suppliesBody) loadTableData('suppliesBody', data.suppliesBody, 12);
// គណនាសរុប
calculateLandTotals();
calculateBuildingTotals();
calculateTechnicalTotals();
calculateVehiclesTotals();
calculateSuppliesTotals();
console.log('✅ បានផ្ទុកទិន្នន័យដោយជោគជ័យ!');
} catch (error) {
console.log('មានបញ្ហាក្នុងការផ្ទុកទិន្នន័យ: ' + error.message);
}
}
function loadTableData(bodyId, rowsData, totalCols) {
const tbody = document.getElementById(bodyId);
tbody.innerHTML = '';
rowsData.forEach((rowData, index) => {
const row = tbody.insertRow();
// បង្កើតក្រឡា
for (let i = 0; i < rowData.length; i++) {
const cell = row.insertCell(i);
cell.innerText = rowData[i] || '';
if (i === 0) {
// លេខរៀង
cell.innerText = index + 1;
} else if (i === 1) {
// ឈ្មោះ/បរិយាយ
cell.className = "editable align-left";
cell.contentEditable = "true";
} else {
cell.className = "editable";
cell.contentEditable = "true";
}
}
// ប៊ូតុងលុប
const lastCell = row.insertCell(rowData.length);
lastCell.innerHTML = `លុប`;
enableAutoCalculateForRow(row);
});
}
// ===============================
// លុបទិន្នន័យ
// ===============================
function clearData() {
if (confirm('⚠️ តើអ្នកប្រាកដថាចង់លុបទិន្នន័យទាំងអស់?')) {
// លុបក្រឡាដែលអាចកែបាន
document.querySelectorAll('[contenteditable="true"]').forEach(cell => {
if (cell.classList.contains('align-left')) {
cell.textContent = '';
} else {
cell.textContent = '0';
}
});
// លុប localStorage
localStorage.removeItem(STORAGE_KEY);
// គណនាសរុបឡើងវិញ
calculateLandTotals();
calculateBuildingTotals();
calculateTechnicalTotals();
calculateVehiclesTotals();
calculateSuppliesTotals();
alert('🗑️ បានលុបទិន្នន័យរួចរាល់!');
}
}
// ===============================
// គណនាស្វ័យប្រវត្តិ
// ===============================
function enableAutoCalculateForRow(row) {
row.querySelectorAll('[contenteditable="true"]').forEach(cell => {
cell.addEventListener('blur', function() {
const tbody = this.closest('tbody');
if (tbody) {
const bodyId = tbody.id;
if (bodyId === 'landBody') calculateLandTotals();
else if (bodyId === 'buildingBody') calculateBuildingTotals();
else if (bodyId === 'technicalBody') calculateTechnicalTotals();
else if (bodyId === 'vehiclesBody') calculateVehiclesTotals();
else if (bodyId === 'suppliesBody') calculateSuppliesTotals();
}
});
cell.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
this.blur();
}
});
});
}
function enableAutoCalculate() {
document.querySelectorAll('tbody tr').forEach(row => {
enableAutoCalculateForRow(row);
});
}
// ===============================
// ការដំណើរការពេលផ្ទុកទំព័រ
// ===============================
window.onload = function() {
enableAutoCalculate();
loadData();
// គណនាសរុបដំបូង
calculateLandTotals();
calculateBuildingTotals();
calculateTechnicalTotals();
calculateVehiclesTotals();
calculateSuppliesTotals();
}
</script>
🔢 គណនាសរុប
💾 រក្សាទុក
📂 ផ្ទុក
🖨️ បោះពុម្ព
🗑️ លុប
ព្រះរាជាណាចក្រកម្ពុជា
ជាតិ សាសនា ព្រះមហាក្សត្រ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment